<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><div id="myscoll"></div><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>数据分析  | Fomalhaut🥝</title><meta name="keywords" content="Python,数据分析"><meta name="author" content="Fomalhaut🥝"><meta name="copyright" content="Fomalhaut🥝"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="ffffff"><meta name="description" content="一 Jupyter notebook 1 本机打开 1234# 进入虚拟环境workon ml# 输入命令jupyter notebook 新建notebook文档  notebook的文档格式是   卸载jupyter  pip uninstall -y jupyter pip uninstall -y jupyter_core pip uninstall -y jupyter-client p">
<meta property="og:type" content="article">
<meta property="og:title" content="数据分析 ">
<meta property="og:url" content="https://xiangmou123.gitee.io/xiangmou/posts/3311.html">
<meta property="og:site_name" content="Fomalhaut🥝">
<meta property="og:description" content="一 Jupyter notebook 1 本机打开 1234# 进入虚拟环境workon ml# 输入命令jupyter notebook 新建notebook文档  notebook的文档格式是   卸载jupyter  pip uninstall -y jupyter pip uninstall -y jupyter_core pip uninstall -y jupyter-client p">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://tuchuang.voooe.cn/images/2023/01/02/avatar.webp">
<meta property="article:published_time" content="2020-03-07T10:29:16.000Z">
<meta property="article:modified_time" content="2023-02-23T01:45:28.580Z">
<meta property="article:author" content="Fomalhaut🥝">
<meta property="article:tag" content="Python">
<meta property="article:tag" content="数据分析">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://tuchuang.voooe.cn/images/2023/01/02/avatar.webp"><link rel="shortcut icon" href="/xiangmou/"><link rel="canonical" href="https://xiangmou123.gitee.io/xiangmou/posts/3311"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/xiangmou/css/index.css"><link rel="stylesheet" href="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/font-awesome/6.0.0/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.staticfile.org/fancyapps-ui/4.0.31/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/xiangmou/',
  algolia: undefined,
  localSearch: {"path":"/xiangmou/search.xml","preload":true,"languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: {"limitDay":365,"position":"top","messagePrev":"It has been","messageNext":"days since the last update, the content of the article may be outdated."},
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":230},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: true,
    post: true
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdnjs.cloudflare.com/ajax/libs/flickr-justified-gallery/2.1.2/fjGallery.min.js',
      css: 'https://cdnjs.cloudflare.com/ajax/libs/flickr-justified-gallery/2.1.2/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '数据分析 ',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-02-23 09:45:28'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', 'ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          const now = new Date()
          const hour = now.getHours()
          const isNight = hour <= 6 || hour >= 18
          if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
          else if (t === 'light') activateLightMode()
          else activateDarkMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="https://cdn1.tianli0.top/npm/element-ui@2.15.6/packages/theme-chalk/lib/index.css"><style id="themeColor"></style><style id="rightSide"></style><style id="transPercent"></style><style id="blurNum"></style><style id="settingStyle"></style><span id="fps"></span><style id="defineBg"></style><style id="menu_shadow"></style><svg aria-hidden="true" style="position:absolute; overflow:hidden; width:0; height:0"><symbol id="icon-sun" viewBox="0 0 1024 1024"><path d="M960 512l-128 128v192h-192l-128 128-128-128H192v-192l-128-128 128-128V192h192l128-128 128 128h192v192z" fill="#FFD878" p-id="8420"></path><path d="M736 512a224 224 0 1 0-448 0 224 224 0 1 0 448 0z" fill="#FFE4A9" p-id="8421"></path><path d="M512 109.248L626.752 224H800v173.248L914.752 512 800 626.752V800h-173.248L512 914.752 397.248 800H224v-173.248L109.248 512 224 397.248V224h173.248L512 109.248M512 64l-128 128H192v192l-128 128 128 128v192h192l128 128 128-128h192v-192l128-128-128-128V192h-192l-128-128z" fill="#4D5152" p-id="8422"></path><path d="M512 320c105.888 0 192 86.112 192 192s-86.112 192-192 192-192-86.112-192-192 86.112-192 192-192m0-32a224 224 0 1 0 0 448 224 224 0 0 0 0-448z" fill="#4D5152" p-id="8423"></path></symbol><symbol id="icon-moon" viewBox="0 0 1024 1024"><path d="M611.370667 167.082667a445.013333 445.013333 0 0 1-38.4 161.834666 477.824 477.824 0 0 1-244.736 244.394667 445.141333 445.141333 0 0 1-161.109334 38.058667 85.077333 85.077333 0 0 0-65.066666 135.722666A462.08 462.08 0 1 0 747.093333 102.058667a85.077333 85.077333 0 0 0-135.722666 65.024z" fill="#FFB531" p-id="11345"></path><path d="M329.728 274.133333l35.157333-35.157333a21.333333 21.333333 0 1 0-30.165333-30.165333l-35.157333 35.157333-35.114667-35.157333a21.333333 21.333333 0 0 0-30.165333 30.165333l35.114666 35.157333-35.114666 35.157334a21.333333 21.333333 0 1 0 30.165333 30.165333l35.114667-35.157333 35.157333 35.157333a21.333333 21.333333 0 1 0 30.165333-30.165333z" fill="#030835" p-id="11346"></path></symbol></svg><!-- hexo injector head_end start --><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiper.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiperstyle.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-wowjs/lib/animate.min.css" media="print" onload="this.media='screen'"><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-filter-gitcalendar/lib/gitcalendar.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-tag-plugins-plus@latest/lib/assets/font-awesome-animation.min.css" media="defer" onload="this.media='all'"><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-tag-plugins-plus@latest/lib/tag_plugins.css" media="defer" onload="this.media='all'"><script src="https://npm.elemecdn.com/hexo-butterfly-tag-plugins-plus@latest/lib/assets/carousel-touch.js"></script><!-- hexo injector head_end end --><meta name="generator" content="Hexo 6.3.0"><link rel="alternate" href="/xiangmou/atom.xml" title="Fomalhaut🥝" type="application/atom+xml">
</head><body><div id="loading-box" onclick="document.getElementById(&quot;loading-box&quot;).classList.add(&quot;loaded&quot;)"><div class="loading-bg"><div class="loading-img"></div><div class="loading-image-dot"></div></div></div><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "" data-lazy-src="https://tuchuang.voooe.cn/images/2023/01/02/avatar.webp" onerror="onerror=null;src='/assets/r1.jpg'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/xiangmou/archives/"><div class="headline">文章</div><div class="length-num">7</div></a><a href="/xiangmou/tags/"><div class="headline">标签</div><div class="length-num">12</div></a><a href="/xiangmou/categories/"><div class="headline">分类</div><div class="length-num">7</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/xiangmou/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-home"></use></svg><span class="menu_word" style="font-size:17px"> 首页</span></a></div><div class="menus_item"><a class="site-page group faa-parent animated-hover hide" href="javascript:void(0);"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon--article"></use></svg><span class="menu_word" style="font-size:17px"> 文章</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/archives/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-guidang1">                   </use></svg><span class="menu_word" style="font-size:17px"> 归档</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/tags/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-sekuaibiaoqian">                   </use></svg><span class="menu_word" style="font-size:17px"> 标签</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/categories/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-fenlei">                   </use></svg><span class="menu_word" style="font-size:17px"> 分类</span></a></li></ul></div><div class="menus_item"><a class="site-page group faa-parent animated-hover hide" href="javascript:void(0);"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-pinweishenghuo"></use></svg><span class="menu_word" style="font-size:17px"> 休闲</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/life/music/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-yinle">                   </use></svg><span class="menu_word" style="font-size:17px"> 八音盒</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/life/movies/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-dianying1">                   </use></svg><span class="menu_word" style="font-size:17px"> 影院</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/life/games/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-youxishoubing">                   </use></svg><span class="menu_word" style="font-size:17px"> 游戏</span></a></li></ul></div><div class="menus_item"><a class="site-page group faa-parent animated-hover hide" href="javascript:void(0);"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-xiangzi"></use></svg><span class="menu_word" style="font-size:17px"> 八宝箱</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/box/gallery/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-tubiaozhizuomoban">                   </use></svg><span class="menu_word" style="font-size:17px"> 画廊</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/box/animation/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-nvwumao">                   </use></svg><span class="menu_word" style="font-size:17px"> 动画</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/box/nav/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-zhifengche">                   </use></svg><span class="menu_word" style="font-size:17px"> 网址导航</span></a></li></ul></div><div class="menus_item"><a class="site-page group faa-parent animated-hover hide" href="javascript:void(0);"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-shejiaoxinxi"></use></svg><span class="menu_word" style="font-size:17px"> 社交</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/social/fcircle/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-pengyouquan">                   </use></svg><span class="menu_word" style="font-size:17px"> 朋友圈</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/comments/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-liuyan">                   </use></svg><span class="menu_word" style="font-size:17px"> 留言板</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/social/link/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-lianjie">                   </use></svg><span class="menu_word" style="font-size:17px"> 友人帐</span></a></li></ul></div><div class="menus_item"><a class="site-page group faa-parent animated-hover hide" href="javascript:void(0);"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-wangye"></use></svg><span class="menu_word" style="font-size:17px"> 网站</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/site/census/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon--tongjibiao">                   </use></svg><span class="menu_word" style="font-size:17px"> 网站统计</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/site/echarts/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-shujutongji1">                   </use></svg><span class="menu_word" style="font-size:17px"> 文章统计</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/site/time/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-xianxingshalou">                   </use></svg><span class="menu_word" style="font-size:17px"> 旧时光</span></a></li></ul></div><div class="menus_item"><a class="site-page group faa-parent animated-hover hide" href="javascript:void(0);"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-maoliang"></use></svg><span class="menu_word" style="font-size:17px"> 个人</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/personal/bb/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-qunliaotian">                   </use></svg><span class="menu_word" style="font-size:17px"> 唠叨</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/personal/love/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-love-sign">                   </use></svg><span class="menu_word" style="font-size:17px"> 恋爱小屋</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/personal/about/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-paperplane">                   </use></svg><span class="menu_word" style="font-size:17px"> 关于</span></a></li></ul></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header"><nav id="nav"><span id="blog_name"><a id="site-name" href="/xiangmou/">Fomalhaut🥝</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/xiangmou/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-home"></use></svg><span class="menu_word" style="font-size:17px"> 首页</span></a></div><div class="menus_item"><a class="site-page group faa-parent animated-hover hide" href="javascript:void(0);"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon--article"></use></svg><span class="menu_word" style="font-size:17px"> 文章</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/archives/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-guidang1">                   </use></svg><span class="menu_word" style="font-size:17px"> 归档</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/tags/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-sekuaibiaoqian">                   </use></svg><span class="menu_word" style="font-size:17px"> 标签</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/categories/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-fenlei">                   </use></svg><span class="menu_word" style="font-size:17px"> 分类</span></a></li></ul></div><div class="menus_item"><a class="site-page group faa-parent animated-hover hide" href="javascript:void(0);"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-pinweishenghuo"></use></svg><span class="menu_word" style="font-size:17px"> 休闲</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/life/music/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-yinle">                   </use></svg><span class="menu_word" style="font-size:17px"> 八音盒</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/life/movies/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-dianying1">                   </use></svg><span class="menu_word" style="font-size:17px"> 影院</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/life/games/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-youxishoubing">                   </use></svg><span class="menu_word" style="font-size:17px"> 游戏</span></a></li></ul></div><div class="menus_item"><a class="site-page group faa-parent animated-hover hide" href="javascript:void(0);"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-xiangzi"></use></svg><span class="menu_word" style="font-size:17px"> 八宝箱</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/box/gallery/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-tubiaozhizuomoban">                   </use></svg><span class="menu_word" style="font-size:17px"> 画廊</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/box/animation/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-nvwumao">                   </use></svg><span class="menu_word" style="font-size:17px"> 动画</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/box/nav/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-zhifengche">                   </use></svg><span class="menu_word" style="font-size:17px"> 网址导航</span></a></li></ul></div><div class="menus_item"><a class="site-page group faa-parent animated-hover hide" href="javascript:void(0);"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-shejiaoxinxi"></use></svg><span class="menu_word" style="font-size:17px"> 社交</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/social/fcircle/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-pengyouquan">                   </use></svg><span class="menu_word" style="font-size:17px"> 朋友圈</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/comments/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-liuyan">                   </use></svg><span class="menu_word" style="font-size:17px"> 留言板</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/social/link/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-lianjie">                   </use></svg><span class="menu_word" style="font-size:17px"> 友人帐</span></a></li></ul></div><div class="menus_item"><a class="site-page group faa-parent animated-hover hide" href="javascript:void(0);"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-wangye"></use></svg><span class="menu_word" style="font-size:17px"> 网站</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/site/census/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon--tongjibiao">                   </use></svg><span class="menu_word" style="font-size:17px"> 网站统计</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/site/echarts/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-shujutongji1">                   </use></svg><span class="menu_word" style="font-size:17px"> 文章统计</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/site/time/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-xianxingshalou">                   </use></svg><span class="menu_word" style="font-size:17px"> 旧时光</span></a></li></ul></div><div class="menus_item"><a class="site-page group faa-parent animated-hover hide" href="javascript:void(0);"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-maoliang"></use></svg><span class="menu_word" style="font-size:17px"> 个人</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/personal/bb/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-qunliaotian">                   </use></svg><span class="menu_word" style="font-size:17px"> 唠叨</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/personal/love/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-love-sign">                   </use></svg><span class="menu_word" style="font-size:17px"> 恋爱小屋</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/xiangmou/personal/about/"><svg class="menu_icon faa-tada" aria-hidden="true" style="width:1.30em;height:1.30em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;"><use xlink:href="#icon-paperplane">                   </use></svg><span class="menu_word" style="font-size:17px"> 关于</span></a></li></ul></div></div><center id="name-container"><a id="page-name" href="javascript:scrollToTop()">PAGE_NAME</a></center><div id="nav-right"><div id="search-button"><a class="search faa-parent animated-hover" title="检索站内任何你想要的信息"><svg class="faa-tada icon" style="height:24px;width:24px;fill:currentColor;position:relative;top:6px" aria-hidden="true"><use xlink:href="#icon-valentine_-search-love-find-heart"></use></svg><span> 搜索</span></a></div><a class="meihua faa-parent animated-hover" onclick="toggleWinbox()" title="美化设置-自定义你的风格" id="meihua-button"><svg class="faa-tada icon" style="height:26px;width:26px;fill:currentColor;position:relative;top:8px" aria-hidden="true"><use xlink:href="#icon-tupian1"></use></svg></a><a class="sun_moon faa-parent animated-hover" onclick="switchNightMode()" title="浅色和深色模式转换" id="nightmode-button"><svg class="faa-tada" style="height:25px;width:25px;fill:currentColor;position:relative;top:7px" viewBox="0 0 1024 1024"><use id="modeicon" xlink:href="#icon-moon">       </use></svg></a><div id="toggle-menu"><a><i class="fas fa-bars fa-fw"></i></a></div></div></div></nav><div id="post-info"><h1 class="post-title">数据分析 </h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><svg class="meta_icon post-meta-icon" style="width:30px;height:30px;position:relative;top:10px"><use xlink:href="#icon-rili"></use></svg><span class="post-meta-label">发表于 </span><time class="post-meta-date-created" datetime="2020-03-07T10:29:16.000Z" title="发表于 2020-03-07 18:29:16">2020-03-07</time><span class="post-meta-separator">|</span><svg class="meta_icon post-meta-icon" style="width:18px;height:18px;position:relative;top:5px"><use xlink:href="#icon-gengxin1"></use></svg><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-02-23T01:45:28.580Z" title="更新于 2023-02-23 09:45:28">2023-02-23</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><svg class="meta_icon post-meta-icon" style="width:18px;height:18px;position:relative;top:5px"><use xlink:href="#icon-biaoqian"></use></svg><a class="post-meta-categories" href="/xiangmou/categories/%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90/">数据分析</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><svg class="meta_icon post-meta-icon" style="width:25px;height:25px;position:relative;top:8px"><use xlink:href="#icon-charuword"></use></svg><span class="post-meta-label">字数总计:</span><span class="word-count">5679</span><span class="post-meta-separator">|</span><svg class="meta_icon post-meta-icon" style="width:20px;height:20px;position:relative;top:5px"><use xlink:href="#icon-shizhong"></use></svg><span class="post-meta-label">阅读时长:</span><span>22分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="数据分析 "><svg class="meta_icon post-meta-icon" style="width:25px;height:25px;position:relative;top:5px"><use xlink:href="#icon-eye"></use></svg><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div><section class="main-hero-waves-area waves-area"><svg class="waves-svg" xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink" viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto"><defs><path id="gentle-wave" d="M -160 44 c 30 0 58 -18 88 -18 s 58 18 88 18 s 58 -18 88 -18 s 58 18 88 18 v 44 h -352 Z"></path></defs><g class="parallax"><use href="#gentle-wave" x="48" y="0"></use><use href="#gentle-wave" x="48" y="3"></use><use href="#gentle-wave" x="48" y="5"></use><use href="#gentle-wave" x="48" y="7"></use></g></svg></section></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1>一 Jupyter notebook</h1>
<h2 id="1-本机打开">1 本机打开</h2>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 进入虚拟环境</span></span><br><span class="line">workon ml</span><br><span class="line"><span class="comment"># 输入命令</span></span><br><span class="line">jupyter notebook</span><br></pre></td></tr></table></figure>
<p>新建notebook文档</p>
<ul>
<li>notebook的文档格式是</li>
</ul>
<blockquote>
<p>卸载jupyter</p>
<ul>
<li>pip uninstall -y jupyter</li>
<li>pip uninstall -y jupyter_core</li>
<li>pip uninstall -y jupyter-client</li>
<li>pip uninstall -y jupyter-console</li>
<li>pip uninstall -y notebook</li>
<li>pip uninstall -y qtconsole</li>
<li>pip uninstall -y nbconvert</li>
<li>pip uninstall -y nbformat</li>
</ul>
</blockquote>
<blockquote>
<p>如何修改默认浏览器的位置？</p>
<p>打开文件C:\Users\Administrator.jupyter\jupyter_notebook_config.py</p>
<p>72行</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">webbrowser.register(<span class="string">&#x27;chrome&#x27;</span>,<span class="literal">None</span>,webbrowser.GenericBrowser(<span class="string">u&#x27;C:/Users/Administrator/AppData/Local/Google/Chrome/Application/chrome.exe&#x27;</span>))</span><br><span class="line"></span><br><span class="line">c.NotebookApp.browser = <span class="string">&#x27;chrome&#x27;</span></span><br></pre></td></tr></table></figure>
</blockquote>
<h2 id="2-cell">2 cell</h2>
<h3 id="2-1cell操作">2.1cell操作</h3>
<p><strong>cell</strong>：一对In Out会话被视作一个代码单元，称为cell</p>
<p>Jupyter支持两种模式：</p>
<ul>
<li>编辑模式（Enter）
<ul>
<li>命令模式下<code>回车Enter</code>或<code>鼠标双击</code>cell进入编辑模式</li>
<li>可以<strong>操作cell内文本</strong>或代码，剪切／复制／粘贴移动等操作</li>
</ul>
</li>
<li>命令模式（Esc）
<ul>
<li>按<code>Esc</code>退出编辑，进入命令模式</li>
<li>可以<strong>操作cell单元本身</strong>进行剪切／复制／粘贴／移动等操作</li>
</ul>
</li>
</ul>
<h3 id="2-2-cell快捷键">2.2 cell快捷键</h3>
<ul>
<li>
<p>两种模式通用快捷键</p>
<ul>
<li><strong>Shift+Enter，执行本单元代码，并跳转到下一单元</strong></li>
<li><strong>Ctrl+Enter，执行本单元代码，留在本单元</strong></li>
</ul>
</li>
<li>
<p>命令模式</p>
<p>：按ESC进入</p>
<ul>
<li><code>Y</code>，cell切换到Code模式</li>
<li><code>M</code>，cell切换到Markdown模式</li>
<li><code>A</code>，在当前cell的上面添加cell</li>
<li><code>B</code>，在当前cell的下面添加cell</li>
<li><code>双击D</code>：删除当前cell</li>
<li><code>Z</code>，回退</li>
<li><code>L</code>，为当前cell加上行号 &lt;!–</li>
<li><code>Ctrl+Shift+P</code>，对话框输入命令直接运行</li>
<li>快速跳转到首个cell，<code>Crtl+Home</code></li>
<li>快速跳转到最后一个cell，<code>Crtl+End</code> --&gt;</li>
</ul>
</li>
<li>
<p>编辑模式</p>
<p>：按Enter进入</p>
<ul>
<li>多光标操作：<code>Ctrl键点击鼠标</code>（Mac:CMD+点击鼠标）</li>
<li>回退：<code>Ctrl+Z</code>（Mac:CMD+Z）</li>
<li>重做：<code>Ctrl+Y</code>（Mac:CMD+Y)</li>
<li>补全代码：变量、方法后跟<code>Tab键</code></li>
<li>为一行或多行代码添加/取消注释：<code>Ctrl+/</code>（Mac:CMD+/）</li>
<li>屏蔽自动输出信息：可在最后一条语句之后加一个分号</li>
</ul>
</li>
</ul>
<h1>二 Matplotlib</h1>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">plt.rcParams[<span class="string">&#x27;font.sans-serif&#x27;</span>] = [<span class="string">&#x27;simhei&#x27;</span>] <span class="comment"># 正常显示中文</span></span><br><span class="line">plt.rcParams[<span class="string">&#x27;axes.unicode_minus&#x27;</span>]=<span class="literal">False</span> <span class="comment">#用来正常显示负号</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h2 id="1-绘图架构">1 绘图架构</h2>
<h3 id="1-1-Matplotlib框架构成">1.1 Matplotlib框架构成</h3>
<p>matplotlib框架分为三层，这三层构成了一个栈，上层可以调用下层。</p>
<p><img src= "" data-lazy-src="E:%5Cpython%5C%E8%AF%BE%E7%A8%8B%E6%96%87%E4%BB%B6%E5%A4%B9%5C%E8%AF%BE%E4%BB%B6%E5%9B%BE%E7%89%87%5C471.png" alt=""></p>
<h4 id="1-后端层">1 后端层</h4>
<p>matplotlib的底层，实现了大量的抽象接口类，这些API用来在底层实现图形元素的一个个类</p>
<ul>
<li>FigureCanvas对象实现了绘图区域这一概念</li>
<li>Renderer对象在FigureCanvas上绘图</li>
</ul>
<h4 id="2-美工层">2 美工层</h4>
<p>图形中所有能看到的元素都属于Artist对象，即标题、轴标签、刻度等组成图形的所有元素都是Artist对象的实例</p>
<ul>
<li>Figure:指整个图形(包括所有的元素,比如标题、线等)</li>
<li>Axes(<strong>坐标系</strong>):数据的绘图区域</li>
<li>Axis(<strong>坐标轴</strong>)：坐标系中的一条轴，包含大小限制、刻度和刻度标签</li>
</ul>
<p>特点为：</p>
<ul>
<li>一个figure(图)可以包含多个axes(坐标系)，但是一个axes只能属于一个figure。</li>
<li>一个axes(坐标系)可以包含多个axis(坐标轴)，包含两个即为2d坐标系，3个即为3d坐标系</li>
</ul>
<h4 id="3-脚本层">3 脚本层</h4>
<p>主要用于可视化编程，pyplot模块可以提供给我们一个与matplotlib打交道的接口。可以只通过调用pyplot模块的函数从而操作整个程序包，来绘制图形。</p>
<ul>
<li>操作或者改动Figure对象，例如创建Figure对象</li>
<li>大部分工作是处理样本文件的图形与坐标的生成</li>
</ul>
<h2 id="2-折线图">2 折线图</h2>
<h3 id="2-1-折线图绘制">2.1 折线图绘制</h3>
<h4 id="1-matplotlib-pyplot模块">1 matplotlib.pyplot模块</h4>
<p>matplotlib.pytplot包含了一系列类似于matlab的画图函数。 它的函数<strong>作用于当前图形(figure)的当前坐标系(axes)</strong>。</p>
<figure class="highlight elm"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> matplotlib.pyplot <span class="keyword">as</span> plt</span><br></pre></td></tr></table></figure>
<h4 id="2-折线图绘制与显示">2 折线图绘制与显示</h4>
<p>展现上海一周的天气,比如从星期一到星期日的天气温度如下</p>
<figure class="highlight apache"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">plt</span>.figure(figsize=(<span class="number">10</span>, <span class="number">10</span>))</span><br><span class="line"><span class="attribute">plt</span>.plot([<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span> ,<span class="number">7</span>],<span class="meta"> [17,17,18,15,11,11,13])</span></span><br><span class="line"><span class="meta">plt.show()</span></span><br></pre></td></tr></table></figure>
<h4 id="3-修改图形大小与图片保存">3 修改图形大小与图片保存</h4>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">plt.figure(figsize=(), dpi=)</span><br><span class="line">    figsize:指定图的长宽</span><br><span class="line">    dpi:图像的清晰度</span><br><span class="line">    返回fig对象</span><br><span class="line">plt.savefig(path)</span><br><span class="line">plt.figure(figsize=(<span class="number">20</span>, <span class="number">8</span>), dpi=<span class="number">80</span>)</span><br><span class="line">plt.savefig(<span class="string">&quot;test.png&quot;</span>)</span><br></pre></td></tr></table></figure>
<h3 id="2-2-温度变化显示">2.2 温度变化显示</h3>
<p>需求：画出某城市11点到12点1小时内每分钟的温度变化折线图，温度范围在15度~18度</p>
<h4 id="1-构造数据、显示">1 构造数据、显示</h4>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 画出温度变化图</span></span><br><span class="line"><span class="comment"># 创建一个figure</span></span><br><span class="line">plt.figure(figsize=(<span class="number">20</span>, <span class="number">8</span>), dpi=<span class="number">80</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 准备x, y坐标的数据</span></span><br><span class="line">x = <span class="built_in">range</span>(<span class="number">60</span>)</span><br><span class="line">y_shanghai = [random.uniform(<span class="number">15</span>, <span class="number">18</span>) <span class="keyword">for</span> i <span class="keyword">in</span> x]</span><br><span class="line"></span><br><span class="line"><span class="comment"># 画折线图</span></span><br><span class="line">plt.plot(x, y_shanghai, label=<span class="string">&quot;上海&quot;</span>)</span><br><span class="line"></span><br><span class="line">plt.show()</span><br></pre></td></tr></table></figure>
<p><img src= "" data-lazy-src="E:%5Cpython%5C%E8%AF%BE%E7%A8%8B%E6%96%87%E4%BB%B6%E5%A4%B9%5C%E8%AF%BE%E4%BB%B6%E5%9B%BE%E7%89%87%5C473.%E4%B8%8A%E6%B5%B72.png" alt=""></p>
<h4 id="2-自定义x-y刻度以及中文显示">2 自定义x,y刻度以及中文显示</h4>
<ul>
<li>
<p>plt.xticks(x, **kwargs)</p>
<p>x:要显示的刻度值</p>
</li>
<li>
<p>plt.yticks(y, **kwargs)</p>
<p>y:要显示的刻度值</p>
</li>
</ul>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 增加以下两行代码</span></span><br><span class="line"><span class="comment"># 构造中文列表的字符串</span></span><br><span class="line">x_ch = [<span class="string">&quot;11点&#123;&#125;分&quot;</span>.<span class="built_in">format</span>(i) <span class="keyword">for</span> i <span class="keyword">in</span> x]</span><br><span class="line">y_ticks = <span class="built_in">range</span>(<span class="number">40</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 修改x,y坐标的刻度</span></span><br><span class="line">plt.xticks(x[::<span class="number">5</span>], x_ch[::<span class="number">5</span>])   $$$$ 因为是替换成了中文，所以要把原来的写在前面</span><br><span class="line">plt.yticks(y_ticks[::<span class="number">5</span>])</span><br></pre></td></tr></table></figure>
<p><img src= "" data-lazy-src="E:%5Cpython%5C%E8%AF%BE%E7%A8%8B%E6%96%87%E4%BB%B6%E5%A4%B9%5C%E8%AF%BE%E4%BB%B6%E5%9B%BE%E7%89%87%5C474.%E4%B8%8A%E6%B5%B73.png" alt=""></p>
<h4 id="3-增加标题、x轴y轴描述信息">3 增加标题、x轴y轴描述信息</h4>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">plt.xlabel(<span class="string">&quot;时间&quot;</span>)</span><br><span class="line">plt.ylabel(<span class="string">&quot;温度&quot;</span>)</span><br><span class="line">plt.title(<span class="string">&quot;中午11点0分到12点之间的温度变化图示&quot;</span>)</span><br></pre></td></tr></table></figure>
<p><img src= "" data-lazy-src="E:%5Cpython%5C%E8%AF%BE%E7%A8%8B%E6%96%87%E4%BB%B6%E5%A4%B9%5C%E8%AF%BE%E4%BB%B6%E5%9B%BE%E7%89%87%5C475.%E4%B8%8A%E6%B5%B74.png" alt=""></p>
<h4 id="4-再添加一个城市的温度变化">4 再添加一个城市的温度变化</h4>
<p>收集到北京当天温度变化情况，温度在1度到3度。怎么去添加另一个在同一坐标系当中的不同图形，<strong>其实很简单只需要再次plot即可</strong>，但是需要区分线条，如下显示</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 生成北京的温度</span></span><br><span class="line">y_beijing = [random.uniform(<span class="number">1</span>, <span class="number">3</span>) <span class="keyword">for</span> i <span class="keyword">in</span> x]</span><br><span class="line"></span><br><span class="line"><span class="comment"># 画折线图</span></span><br><span class="line">plt.plot(x, y_shanghai, label=<span class="string">&quot;上海&quot;</span>)</span><br><span class="line"><span class="comment"># 使用plot可以多次画多个折线</span></span><br><span class="line">plt.plot(x, y_beijing, color=<span class="string">&#x27;r&#x27;</span>, linestyle=<span class="string">&#x27;--&#x27;</span>, label=<span class="string">&quot;北京&quot;</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 添加图形注释</span></span><br><span class="line">plt.legend(loc=<span class="string">&quot;best&quot;</span>)</span><br><span class="line"><span class="comment"># 删除图上的图例</span></span><br><span class="line">plt.legend_.remove()</span><br></pre></td></tr></table></figure>
<p><strong>自定一个图形风格</strong></p>
<table>
<thead>
<tr>
<th>颜色字符</th>
<th>风格字符</th>
</tr>
</thead>
<tbody>
<tr>
<td>r 红色</td>
<td>- 实线</td>
</tr>
<tr>
<td>g 绿色</td>
<td>- - 虚线</td>
</tr>
<tr>
<td>b 蓝色</td>
<td>-. 点划线</td>
</tr>
<tr>
<td>w 白色</td>
<td>: 点虚线</td>
</tr>
<tr>
<td>c 青色</td>
<td>’ ’ 留空、空格</td>
</tr>
<tr>
<td>m 洋红</td>
<td></td>
</tr>
<tr>
<td>y 黄色</td>
<td></td>
</tr>
<tr>
<td>k 黑色</td>
<td></td>
</tr>
</tbody>
</table>
<h4 id="5-添加图例">5 添加图例</h4>
<figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">plt.legend(<span class="attribute">loc</span>=<span class="string">&quot;best&quot;</span>)</span><br></pre></td></tr></table></figure>
<p><img src= "" data-lazy-src="E:%5Cpython%5C%E8%AF%BE%E7%A8%8B%E6%96%87%E4%BB%B6%E5%A4%B9%5C%E8%AF%BE%E4%BB%B6%E5%9B%BE%E7%89%87%5C476.legend.png" alt=""></p>
<p>整体代码：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> matplotlib.pyplot <span class="keyword">as</span> plt</span><br><span class="line"><span class="keyword">import</span> random</span><br><span class="line"></span><br><span class="line">plt.rc(<span class="string">&#x27;font&#x27;</span>, family=<span class="string">&#x27;SimHei&#x27;</span>, size=<span class="number">13</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 1 创建画布</span></span><br><span class="line">plt.figure(figsize=(<span class="number">20</span>,<span class="number">8</span>),dpi=<span class="number">100</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 2 准备数值，生成图表</span></span><br><span class="line">x = <span class="built_in">range</span>(<span class="number">60</span>)</span><br><span class="line">y_shanghai = [random.uniform(<span class="number">10</span>,<span class="number">15</span>) <span class="keyword">for</span> i <span class="keyword">in</span> x]</span><br><span class="line">y_beijing = [random.uniform(<span class="number">15</span>,<span class="number">20</span>) <span class="keyword">for</span> i <span class="keyword">in</span> x]</span><br><span class="line"></span><br><span class="line">plt.plot(x,y_shanghai,label=<span class="string">&quot;上海&quot;</span>)</span><br><span class="line">plt.plot(x,y_beijing,label=<span class="string">&quot;北京&quot;</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 3 自定义x,y轴刻度</span></span><br><span class="line">y_ticks = <span class="built_in">range</span>(<span class="number">40</span>)</span><br><span class="line">x_ticks = [<span class="string">&quot;11点&#123;&#125;分&quot;</span>.<span class="built_in">format</span>(i) <span class="keyword">for</span> i <span class="keyword">in</span> x]</span><br><span class="line">plt.yticks(y_ticks[::<span class="number">5</span>])</span><br><span class="line">plt.xticks(x[::<span class="number">5</span>],x_ticks[::<span class="number">5</span>])</span><br><span class="line"></span><br><span class="line"><span class="comment"># 4 增加网格线</span></span><br><span class="line">plt.grid(<span class="literal">True</span>,linestyle=<span class="string">&quot;--&quot;</span>,alpha=<span class="number">1</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 5 添加x，y，标题轴的描述</span></span><br><span class="line">plt.xlabel(<span class="string">&quot;时间&quot;</span>)</span><br><span class="line">plt.ylabel(<span class="string">&quot;温度&quot;</span>)</span><br><span class="line">plt.title(<span class="string">&quot;一小时内温度变化曲线&quot;</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 6 添加图例</span></span><br><span class="line">plt.legend(loc=<span class="string">&quot;best&quot;</span>)</span><br><span class="line">plt.show()</span><br></pre></td></tr></table></figure>
<h3 id="2-3-多个坐标系显示">2.3 多个坐标系显示</h3>
<p>完整代码：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> matplotlib.pyplot <span class="keyword">as</span> plt</span><br><span class="line"><span class="keyword">import</span> random</span><br><span class="line"></span><br><span class="line"><span class="comment"># 1 创建一行两列画布</span></span><br><span class="line">fig,axes = plt.subplots(nrows=<span class="number">1</span>,ncols=<span class="number">2</span>,figsize=(<span class="number">20</span>,<span class="number">8</span>),dpi=<span class="number">100</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 2 生成数据</span></span><br><span class="line">x = <span class="built_in">range</span>(<span class="number">61</span>)</span><br><span class="line">y_beijing = [random.uniform(<span class="number">10</span>,<span class="number">15</span>) <span class="keyword">for</span> i <span class="keyword">in</span> x]</span><br><span class="line">y_shanghai = [random.uniform(<span class="number">15</span>,<span class="number">20</span>) <span class="keyword">for</span> i <span class="keyword">in</span> x]</span><br><span class="line"></span><br><span class="line"><span class="comment"># 3 将数据添加到图表</span></span><br><span class="line">axes[<span class="number">0</span>].plot(x,y_shanghai,label=<span class="string">&quot;上海&quot;</span>)  $$$ 表示把数据加入到第一张图表里</span><br><span class="line">axes[<span class="number">1</span>].plot(x,y_beijing,label=<span class="string">&quot;北京&quot;</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 4.1 修改y轴坐标</span></span><br><span class="line">y_ticks = <span class="built_in">range</span>(<span class="number">40</span>)</span><br><span class="line">axes[<span class="number">0</span>].set_yticks(y_ticks[::<span class="number">5</span>])</span><br><span class="line">axes[<span class="number">1</span>].set_yticks(y_ticks[::<span class="number">5</span>])</span><br><span class="line"></span><br><span class="line"><span class="comment"># 4.2 修改x轴坐标</span></span><br><span class="line">x_ch = [<span class="string">&quot;11时&#123;&#125;分&quot;</span>.<span class="built_in">format</span>(i) <span class="keyword">for</span> i <span class="keyword">in</span> x]</span><br><span class="line">axes[<span class="number">0</span>].set_xticks(x[::<span class="number">10</span>])   <span class="comment"># 这里比较麻烦，先改数字型的格式，</span></span><br><span class="line">axes[<span class="number">0</span>].set_xticklabels(x_ch[::<span class="number">10</span>])  <span class="comment"># 再改对应的格式化</span></span><br><span class="line">axes[<span class="number">1</span>].set_xticks(x[::<span class="number">10</span>])</span><br><span class="line">axes[<span class="number">1</span>].set_xticklabels(x_ch[::<span class="number">10</span>])</span><br><span class="line"></span><br><span class="line"><span class="comment"># 5 添加x,y的描述</span></span><br><span class="line">axes[<span class="number">0</span>].set_title(<span class="string">&quot;北京温度表&quot;</span>)</span><br><span class="line">axes[<span class="number">1</span>].set_title(<span class="string">&quot;上海温度表&quot;</span>)</span><br><span class="line">axes[<span class="number">0</span>].set_xlabel(<span class="string">&quot;时间&quot;</span>)</span><br><span class="line">axes[<span class="number">1</span>].set_xlabel(<span class="string">&quot;时间&quot;</span>)</span><br><span class="line">axes[<span class="number">0</span>].set_ylabel(<span class="string">&quot;温度&quot;</span>)</span><br><span class="line">axes[<span class="number">1</span>].set_ylabel(<span class="string">&quot;温度&quot;</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 6 添加图例</span></span><br><span class="line">axes[<span class="number">0</span>].legend()</span><br><span class="line">axes[<span class="number">1</span>].legend()</span><br><span class="line"></span><br><span class="line"><span class="comment"># 7 添加风格线</span></span><br><span class="line">axes[<span class="number">0</span>].grid(linestyle=<span class="string">&quot;--&quot;</span>, alpha=<span class="number">0.7</span>)</span><br><span class="line">axes[<span class="number">1</span>].grid(alpha=<span class="number">0.5</span>)</span><br><span class="line"><span class="comment"># 展示数据</span></span><br><span class="line">plt.show()</span><br></pre></td></tr></table></figure>
<p>可以通过subplots函数实现(旧的版本中有subplot，使用起来不方便)，推荐subplots函数</p>
<ul>
<li>matplotlib.pyplot.subplots(nrows=1, ncols=1, **fig_kw) 创建一个带有多个坐标系的图</li>
</ul>
<p>如果我们想要将上海和北京的天气图显示在同一个图的不同坐标系当中，效果如下：</p>
<p><img src= "" data-lazy-src="E:%5Cpython%5C%E8%AF%BE%E7%A8%8B%E6%96%87%E4%BB%B6%E5%A4%B9%5C%E8%AF%BE%E4%BB%B6%E5%9B%BE%E7%89%87%5C477.subplots.png" alt=""></p>
<ul>
<li>
<p>sharex, sharey：</p>
<p>设置为 True 或者 ‘all’ 时，所有子图共享 x 轴或者 y 轴，<br>
设置为 False or ‘none’ 时，所有子图的 x，y 轴均为独立，<br>
设置为 ‘row’ 时，每一行的子图会共享 x 或者 y 轴，<br>
设置为 ‘col’ 时，每一列的子图会共享 x 或者 y 轴。</p>
</li>
</ul>
<blockquote>
<p><strong>plt.subplots_adjust(top=1)</strong></p>
<p>设置图形的比例，纵向</p>
</blockquote>
<h2 id="3-散点图">3 散点图</h2>
<p>实例代码：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># import matplotlib.pyplot as plt</span></span><br><span class="line"><span class="comment"># 1 准备数据</span></span><br><span class="line">x = [<span class="number">225.98</span>,<span class="number">247.07</span>,<span class="number">253.14</span>,<span class="number">457.85</span>]</span><br><span class="line">y = [<span class="number">196.63</span>,<span class="number">203.88</span>,<span class="number">210.75</span>,<span class="number">373.74</span>]</span><br><span class="line"><span class="comment"># 2 创建画布</span></span><br><span class="line">plt.figure(figsize=(<span class="number">20</span>,<span class="number">8</span>),dpi=<span class="number">100</span>)</span><br><span class="line"><span class="comment"># 3 绘制图表</span></span><br><span class="line">plt.scatter(x,y)</span><br><span class="line"><span class="comment"># 4 图表展示</span></span><br><span class="line">plt.show()</span><br></pre></td></tr></table></figure>
<p><img src= "" data-lazy-src="E:%5Cpython%5C%E8%AF%BE%E7%A8%8B%E6%96%87%E4%BB%B6%E5%A4%B9%5C%E8%AF%BE%E4%BB%B6%E5%9B%BE%E7%89%87%5C478.png" alt=""></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 带颜色的散点图，并且有颜色条</span></span><br><span class="line">plt.figure(figsize=(<span class="number">6</span>,<span class="number">4</span>),dpi=<span class="number">100</span>)</span><br><span class="line">plt.scatter(x=temp[<span class="string">&quot;Recommended Mean&quot;</span>],y=temp[<span class="string">&quot;Rating Mean&quot;</span>],alpha=<span class="number">0.5</span>,c =temp[<span class="string">&quot;Count&quot;</span>])</span><br><span class="line">cbar = plt.colorbar()</span><br><span class="line">cbar.set_label(<span class="string">&#x27;Count&#x27;</span>,rotation=<span class="number">90</span>)</span><br><span class="line">plt.xlabel(<span class="string">&quot;推荐平均值&quot;</span>)</span><br><span class="line">plt.ylabel(<span class="string">&quot;评分平均值&quot;</span>)</span><br><span class="line">plt.axhline(y=<span class="number">3.3</span>)</span><br><span class="line">plt.axvline(x=<span class="number">0.55</span>)</span><br><span class="line">plt.text(<span class="number">0.1</span>,<span class="number">1.2</span>,<span class="string">&quot;低分不推荐象限&quot;</span>,ha=<span class="string">&quot;left&quot;</span>)</span><br><span class="line">plt.show()</span><br><span class="line">temp[(temp[<span class="string">&quot;Rating Mean&quot;</span>] &lt; <span class="number">3.3</span>) | (temp[<span class="string">&quot;Recommended Mean&quot;</span>] &lt;= <span class="number">.55</span>)].describe()</span><br></pre></td></tr></table></figure>
<p><img src= "" data-lazy-src="E:/python/%E8%AF%BE%E7%A8%8B%E6%96%87%E4%BB%B6%E5%A4%B9/%E8%AF%BE%E4%BB%B6%E5%9B%BE%E7%89%87/946.png" alt=""></p>
<h2 id="4-柱形图">4 柱形图</h2>
<h3 id="4-1-常见图形种类及意义">4.1 常见图形种类及意义</h3>
<p><img src= "" data-lazy-src="E:%5Cpython%5C%E8%AF%BE%E7%A8%8B%E6%96%87%E4%BB%B6%E5%A4%B9%5C%E8%AF%BE%E4%BB%B6%E5%9B%BE%E7%89%87%5C479.%E5%9B%BE%E5%BD%A2%E7%A7%8D%E7%B1%BB.png" alt=""></p>
<ul>
<li>
<p>折线图:以折线的上升或下降来表示统计数量的增减变化的统计图</p>
<p><strong>特点:能够显示数据的变化趋势，反映事物的变化情况。(变化)</strong></p>
<p>plt.plot</p>
</li>
<li>
<p>直方图:由一系列高度不等的纵向条纹或线段表示数据分布的情况。 一般用横轴表示数据范围，纵轴表示分布情况。</p>
<p><strong>特点:绘制,连续性的数据展示一组或者多组数据的分布状况(统计)</strong></p>
<p>plt.hist</p>
</li>
<li>
<p>柱状图:排列在工作表的列或行中的数据可以绘制到柱状图中。</p>
<p><strong>特点:绘制连离散的数据,能够一眼看出各个数据的大小,比较数据之间的差别。(统计)</strong></p>
<p>plt.bar</p>
</li>
<li>
<p>散点图:用两组数据构成多个坐标点，考察坐标点的分布,判断两变量之间是否存在某种关联或总结坐标点的分布模式。</p>
<p><strong>特点:判断变量之间是否存在数量关联趋势,展示离群点(分布规律)</strong></p>
<p>plt.scatter</p>
</li>
</ul>
<h3 id="4-2-电影票柱形图">4.2 电影票柱形图</h3>
<h4 id="1-需求">1 需求</h4>
<p>每部电影的票房收入对比？</p>
<p>1、画出每部电影的票房收入对比，效果如下：</p>
<p><img src= "" data-lazy-src="E:%5Cpython%5C%E8%AF%BE%E7%A8%8B%E6%96%87%E4%BB%B6%E5%A4%B9%5C%E8%AF%BE%E4%BB%B6%E5%9B%BE%E7%89%87%5C480.%E7%94%B5%E5%BD%B1%E7%A5%A8%E6%88%BF%E6%9D%A1%E5%BD%A2%E5%9B%BE.png" alt=""></p>
<h4 id="2-绘制">2 绘制</h4>
<ul>
<li>matplotlib.pyplot.bar(x, y,width, align=‘center’, **kwargs)</li>
</ul>
<p>绘制柱状图</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">Parameters:    </span><br><span class="line">x : sequence of scalars.</span><br><span class="line"></span><br><span class="line">width : scalar <span class="keyword">or</span> array-like, optional</span><br><span class="line">柱状图的宽度</span><br><span class="line"></span><br><span class="line">align : &#123;‘center’, ‘edge’&#125;, optional, default: ‘center’</span><br><span class="line">Alignment of the bars to the x coordinates:</span><br><span class="line">‘center’: Center the base on the x positions.</span><br><span class="line">‘edge’: Align the left edges of the bars <span class="keyword">with</span> the x positions.</span><br><span class="line">每个柱状图的位置对齐方式</span><br><span class="line"></span><br><span class="line">**kwargs :</span><br><span class="line">color:选择柱状图的颜色</span><br><span class="line"></span><br><span class="line">Returns:    </span><br><span class="line">`.BarContainer`</span><br><span class="line">Container <span class="keyword">with</span> <span class="built_in">all</span> the bars <span class="keyword">and</span> optionally errorbars.</span><br></pre></td></tr></table></figure>
<p>代码：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 完成简单的条形图展现不同的电影票房之间的对比</span></span><br><span class="line">plt.figure(figsize=(<span class="number">20</span>, <span class="number">8</span>), dpi=<span class="number">80</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 准备电影的名字以及电影的票房数据</span></span><br><span class="line">movie_name = [<span class="string">&#x27;雷神3：诸神黄昏&#x27;</span>,<span class="string">&#x27;正义联盟&#x27;</span>,<span class="string">&#x27;东方快车谋杀案&#x27;</span>,<span class="string">&#x27;寻梦环游记&#x27;</span>,<span class="string">&#x27;全球风暴&#x27;</span>,<span class="string">&#x27;降魔传&#x27;</span>,<span class="string">&#x27;追捕&#x27;</span>,<span class="string">&#x27;七十七天&#x27;</span>,<span class="string">&#x27;密战&#x27;</span>,<span class="string">&#x27;狂兽&#x27;</span>,<span class="string">&#x27;其它&#x27;</span>]</span><br><span class="line">y = [<span class="number">73853</span>,<span class="number">57767</span>,<span class="number">22354</span>,<span class="number">15969</span>,<span class="number">14839</span>,<span class="number">8725</span>,<span class="number">8716</span>,<span class="number">8318</span>,<span class="number">7916</span>,<span class="number">6764</span>,<span class="number">52222</span>]</span><br><span class="line"><span class="comment"># 放进横坐标的数字列表</span></span><br><span class="line">x = <span class="built_in">range</span>(<span class="built_in">len</span>(movie_name))</span><br><span class="line"></span><br><span class="line"><span class="comment"># 画出条形图</span></span><br><span class="line">plt.bar(x, y, width=<span class="number">0.5</span>, color=[<span class="string">&#x27;b&#x27;</span>,<span class="string">&#x27;r&#x27;</span>,<span class="string">&#x27;g&#x27;</span>,<span class="string">&#x27;y&#x27;</span>,<span class="string">&#x27;c&#x27;</span>,<span class="string">&#x27;m&#x27;</span>,<span class="string">&#x27;y&#x27;</span>,<span class="string">&#x27;k&#x27;</span>,<span class="string">&#x27;c&#x27;</span>,<span class="string">&#x27;g&#x27;</span>,<span class="string">&#x27;g&#x27;</span>])</span><br><span class="line"></span><br><span class="line"><span class="comment"># 修改刻度名称</span></span><br><span class="line">plt.xticks(x, movie_name)</span><br><span class="line"></span><br><span class="line">plt.show()</span><br></pre></td></tr></table></figure>
<h4 id="3-比较相同天数的票房">3 比较相同天数的票房</h4>
<p>3.1数据如下</p>
<figure class="highlight stylus"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">movie_name = <span class="selector-attr">[<span class="string">&#x27;雷神3：诸神黄昏&#x27;</span>,<span class="string">&#x27;正义联盟&#x27;</span>,<span class="string">&#x27;寻梦环游记&#x27;</span>]</span></span><br><span class="line"></span><br><span class="line">first_day = <span class="selector-attr">[10587.6,10062.5,1275.7]</span></span><br><span class="line">first_weekend=<span class="selector-attr">[36224.9,34479.6,11830]</span></span><br><span class="line"></span><br><span class="line">数据来源: https:<span class="comment">//piaofang.maoyan.com/?ver=normal</span></span><br></pre></td></tr></table></figure>
<p><img src= "" data-lazy-src="E:%5Cpython%5C%E8%AF%BE%E7%A8%8B%E6%96%87%E4%BB%B6%E5%A4%B9%5C%E8%AF%BE%E4%BB%B6%E5%9B%BE%E7%89%87%5C481.%E9%A6%96%E6%97%A5%E9%A6%96%E5%91%A8%E7%A5%A8%E6%88%BF%E5%AF%B9%E6%AF%94.png" alt=""></p>
<p>3.2 分析</p>
<ul>
<li>添加首日首周两部分的柱状图</li>
<li>x轴中文坐标位置调整</li>
</ul>
<p>代码：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 三部电影的首日和首周票房对比</span></span><br><span class="line">plt.figure(figsize=(<span class="number">20</span>, <span class="number">8</span>), dpi=<span class="number">80</span>)</span><br><span class="line"></span><br><span class="line">movie_name = [<span class="string">&#x27;雷神3：诸神黄昏&#x27;</span>,<span class="string">&#x27;正义联盟&#x27;</span>,<span class="string">&#x27;寻梦环游记&#x27;</span>]</span><br><span class="line"></span><br><span class="line">first_day = [<span class="number">10587.6</span>,<span class="number">10062.5</span>,<span class="number">1275.7</span>]</span><br><span class="line">first_weekend=[<span class="number">36224.9</span>,<span class="number">34479.6</span>,<span class="number">11830</span>]</span><br><span class="line"></span><br><span class="line">x = <span class="built_in">range</span>(<span class="built_in">len</span>(movie_name))</span><br><span class="line"></span><br><span class="line"><span class="comment"># 画出柱状图</span></span><br><span class="line">plt.bar(x, first_day, width=<span class="number">0.2</span>, label=<span class="string">&quot;首日票房&quot;</span>)</span><br><span class="line"><span class="comment"># 首周柱状图显示的位置在首日的位置右边  </span></span><br><span class="line">$$$ 再添加一个柱形图，x的起始位置变了，向右移动左边柱形图的宽度，这样两个柱形图就挨着了</span><br><span class="line">plt.bar([i+<span class="number">0.2</span> <span class="keyword">for</span> i <span class="keyword">in</span> x], first_weekend, width=<span class="number">0.2</span>, label=<span class="string">&quot;首周票房&quot;</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 显示X轴中文，固定在首日和首周的中间位置</span></span><br><span class="line">plt.xticks([i+<span class="number">0.1</span> <span class="keyword">for</span> i <span class="keyword">in</span> x], movie_name)</span><br><span class="line">plt.legend(loc=<span class="string">&#x27;best&#x27;</span>)</span><br><span class="line"></span><br><span class="line">plt.show()</span><br></pre></td></tr></table></figure>
<h2 id="5-直方图">5 直方图</h2>
<h3 id="5-1-直方图-Histogram-介绍">5.1 直方图(Histogram)介绍</h3>
<p>直方图，形状类似柱状图却有着与柱状图完全不同的含义。直方图牵涉统计学的概念，首先要对数据进行分组，然后统计每个分组内数据元的数量。 在坐标系中，横轴标出每个组的端点，纵轴表示频数，每个矩形的高代表对应的频数，称这样的统计图为频数分布直方图。</p>
<h3 id="相关概念：">相关概念：</h3>
<ul>
<li>组数：在统计数据时，我们把数据按照不同的范围分成几个组，分成的组的个数称为组数</li>
<li>组距：每一组两个端点的差</li>
</ul>
<p><img src= "" data-lazy-src="E:%5Cpython%5C%E8%AF%BE%E7%A8%8B%E6%96%87%E4%BB%B6%E5%A4%B9%5C%E8%AF%BE%E4%BB%B6%E5%9B%BE%E7%89%87%5C482.%E7%9B%B4%E6%96%B9%E5%9B%BE.png" alt="直方图"></p>
<h3 id="5-2-电影时长分布绘制">5.2 电影时长分布绘制</h3>
<p>现有250部电影的时长,希望统计出这些电影时长的分布状态(比如时长为100分钟到120分钟电影的数量,出现的频率)等信息,你应该如何呈现这些数据?</p>
<p>数据：</p>
<figure class="highlight apache"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">time</span> =[<span class="number">131</span>,  <span class="number">98</span>, <span class="number">125</span>, <span class="number">131</span>, <span class="number">124</span>, <span class="number">139</span>, <span class="number">131</span>, <span class="number">117</span>, <span class="number">128</span>, <span class="number">108</span>, <span class="number">135</span>, <span class="number">138</span>, <span class="number">131</span>, <span class="number">102</span>, <span class="number">107</span>, <span class="number">114</span>, <span class="number">119</span>, <span class="number">128</span>, <span class="number">121</span>, <span class="number">142</span>, <span class="number">127</span>, <span class="number">130</span>, <span class="number">124</span>, <span class="number">101</span>, <span class="number">110</span>, <span class="number">116</span>, <span class="number">117</span>, <span class="number">110</span>, <span class="number">128</span>, <span class="number">128</span>, <span class="number">115</span>,  <span class="number">99</span>, <span class="number">136</span>, <span class="number">126</span>, <span class="number">134</span>,  <span class="number">95</span>, <span class="number">138</span>, <span class="number">117</span>, <span class="number">111</span>,<span class="number">78</span>, <span class="number">132</span>, <span class="number">124</span>, <span class="number">113</span>, <span class="number">150</span>, <span class="number">110</span>, <span class="number">117</span>,  <span class="number">86</span>,  <span class="number">95</span>, <span class="number">144</span>, <span class="number">105</span>, <span class="number">126</span>, <span class="number">130</span>,<span class="number">126</span>, <span class="number">130</span>, <span class="number">126</span>, <span class="number">116</span>, <span class="number">123</span>, <span class="number">106</span>, <span class="number">112</span>, <span class="number">138</span>, <span class="number">123</span>,  <span class="number">86</span>, <span class="number">101</span>,  <span class="number">99</span>, <span class="number">136</span>,<span class="number">123</span>, <span class="number">117</span>, <span class="number">119</span>, <span class="number">105</span>, <span class="number">137</span>, <span class="number">123</span>, <span class="number">128</span>, <span class="number">125</span>, <span class="number">104</span>, <span class="number">109</span>, <span class="number">134</span>, <span class="number">125</span>, <span class="number">127</span>,<span class="number">105</span>, <span class="number">120</span>, <span class="number">107</span>, <span class="number">129</span>, <span class="number">116</span>, <span class="number">108</span>, <span class="number">132</span>, <span class="number">103</span>, <span class="number">136</span>, <span class="number">118</span>, <span class="number">102</span>, <span class="number">120</span>, <span class="number">114</span>,<span class="number">105</span>, <span class="number">115</span>, <span class="number">132</span>, <span class="number">145</span>, <span class="number">119</span>, <span class="number">121</span>, <span class="number">112</span>, <span class="number">139</span>, <span class="number">125</span>, <span class="number">138</span>, <span class="number">109</span>, <span class="number">132</span>, <span class="number">134</span>,<span class="number">156</span>, <span class="number">106</span>, <span class="number">117</span>, <span class="number">127</span>, <span class="number">144</span>, <span class="number">139</span>, <span class="number">139</span>, <span class="number">119</span>, <span class="number">140</span>,  <span class="number">83</span>, <span class="number">110</span>, <span class="number">102</span>,<span class="number">123</span>,<span class="number">107</span>, <span class="number">143</span>, <span class="number">115</span>, <span class="number">136</span>, <span class="number">118</span>, <span class="number">139</span>, <span class="number">123</span>, <span class="number">112</span>, <span class="number">118</span>, <span class="number">125</span>, <span class="number">109</span>, <span class="number">119</span>, <span class="number">133</span>,<span class="number">112</span>, <span class="number">114</span>, <span class="number">122</span>, <span class="number">109</span>, <span class="number">106</span>, <span class="number">123</span>, <span class="number">116</span>, <span class="number">131</span>, <span class="number">127</span>, <span class="number">115</span>, <span class="number">118</span>, <span class="number">112</span>, <span class="number">135</span>,<span class="number">115</span>, <span class="number">146</span>, <span class="number">137</span>, <span class="number">116</span>, <span class="number">103</span>, <span class="number">144</span>,  <span class="number">83</span>, <span class="number">123</span>, <span class="number">111</span>, <span class="number">110</span>, <span class="number">111</span>, <span class="number">100</span>, <span class="number">154</span>,<span class="number">136</span>, <span class="number">100</span>, <span class="number">118</span>, <span class="number">119</span>, <span class="number">133</span>, <span class="number">134</span>, <span class="number">106</span>, <span class="number">129</span>, <span class="number">126</span>, <span class="number">110</span>, <span class="number">111</span>, <span class="number">109</span>, <span class="number">141</span>,<span class="number">120</span>, <span class="number">117</span>, <span class="number">106</span>, <span class="number">149</span>, <span class="number">122</span>, <span class="number">122</span>, <span class="number">110</span>, <span class="number">118</span>, <span class="number">127</span>, <span class="number">121</span>, <span class="number">114</span>, <span class="number">125</span>, <span class="number">126</span>,<span class="number">114</span>, <span class="number">140</span>, <span class="number">103</span>, <span class="number">130</span>, <span class="number">141</span>, <span class="number">117</span>, <span class="number">106</span>, <span class="number">114</span>, <span class="number">121</span>, <span class="number">114</span>, <span class="number">133</span>, <span class="number">137</span>,  <span class="number">92</span>,<span class="number">121</span>, <span class="number">112</span>, <span class="number">146</span>,  <span class="number">97</span>, <span class="number">137</span>, <span class="number">105</span>,  <span class="number">98</span>, <span class="number">117</span>, <span class="number">112</span>,  <span class="number">81</span>,  <span class="number">97</span>, <span class="number">139</span>, <span class="number">113</span>,<span class="number">134</span>, <span class="number">106</span>, <span class="number">144</span>, <span class="number">110</span>, <span class="number">137</span>, <span class="number">137</span>, <span class="number">111</span>, <span class="number">104</span>, <span class="number">117</span>, <span class="number">100</span>, <span class="number">111</span>, <span class="number">101</span>, <span class="number">110</span>,<span class="number">105</span>, <span class="number">129</span>, <span class="number">137</span>, <span class="number">112</span>, <span class="number">120</span>, <span class="number">113</span>, <span class="number">133</span>, <span class="number">112</span>,  <span class="number">83</span>,  <span class="number">94</span>, <span class="number">146</span>, <span class="number">133</span>, <span class="number">101</span>,<span class="number">131</span>, <span class="number">116</span>, <span class="number">111</span>,  <span class="number">84</span>, <span class="number">137</span>, <span class="number">115</span>, <span class="number">122</span>, <span class="number">106</span>, <span class="number">144</span>, <span class="number">109</span>, <span class="number">123</span>, <span class="number">116</span>, <span class="number">111</span>,<span class="number">111</span>, <span class="number">133</span>, <span class="number">150</span>]</span><br></pre></td></tr></table></figure>
<p>效果：</p>
<p><img src= "" data-lazy-src="E:%5Cpython%5C%E8%AF%BE%E7%A8%8B%E6%96%87%E4%BB%B6%E5%A4%B9%5C%E8%AF%BE%E4%BB%B6%E5%9B%BE%E7%89%87%5C483.%E7%94%B5%E5%BD%B1%E6%97%B6%E9%95%BF%E5%88%86%E5%B8%83.png" alt="电影时长分布"></p>
<h4 id="1-matplotlib-pyplot-hist-x-bins-None-normed-None-kwargs">1 matplotlib.pyplot.hist(x, bins=None, normed=None, **kwargs)</h4>
<p>直方图绘制</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">Parameters:    </span><br><span class="line">x : (n,) array <span class="keyword">or</span> sequence of (n,) arrays</span><br><span class="line"></span><br><span class="line">bins : integer <span class="keyword">or</span> sequence <span class="keyword">or</span> ‘auto’, optional</span><br><span class="line">组距</span><br><span class="line"></span><br><span class="line">normed : <span class="built_in">bool</span>, optional</span><br><span class="line">以频率显示或者以頻数显示,默认頻数,值<span class="number">1</span>为频率</span><br></pre></td></tr></table></figure>
<h4 id="2-分析">2 分析</h4>
<ul>
<li>设置组距</li>
<li>设置组数（通常对于数据较少的情况，分为5~12组，数据较多，更换图形显示方式）
<ul>
<li>通常设置组数会有相应公式：组数 = 极差/组距= (max-min)/bins</li>
</ul>
</li>
</ul>
<p>代码：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 展现不同电影的时长分布状态</span></span><br><span class="line">plt.figure(figsize=(<span class="number">20</span>, <span class="number">8</span>), dpi=<span class="number">100</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 准备时长数据</span></span><br><span class="line">time =[<span class="number">131</span>,  <span class="number">98</span>, <span class="number">125</span>, <span class="number">131</span>, <span class="number">124</span>, <span class="number">139</span>, <span class="number">131</span>, <span class="number">117</span>, <span class="number">128</span>, <span class="number">108</span>, <span class="number">135</span>, <span class="number">138</span>, <span class="number">131</span>, <span class="number">102</span>, <span class="number">107</span>, <span class="number">114</span>, <span class="number">119</span>, <span class="number">128</span>, <span class="number">121</span>, <span class="number">142</span>, <span class="number">127</span>, <span class="number">130</span>, <span class="number">124</span>, <span class="number">101</span>, <span class="number">110</span>, <span class="number">116</span>, <span class="number">117</span>, <span class="number">110</span>, <span class="number">128</span>, <span class="number">128</span>, <span class="number">115</span>,  <span class="number">99</span>, <span class="number">136</span>, <span class="number">126</span>, <span class="number">134</span>,  <span class="number">95</span>, <span class="number">138</span>, <span class="number">117</span>, <span class="number">111</span>,<span class="number">78</span>, <span class="number">132</span>, <span class="number">124</span>, <span class="number">113</span>, <span class="number">150</span>, <span class="number">110</span>, <span class="number">117</span>,  <span class="number">86</span>,  <span class="number">95</span>, <span class="number">144</span>, <span class="number">105</span>, <span class="number">126</span>, <span class="number">130</span>,<span class="number">126</span>, <span class="number">130</span>, <span class="number">126</span>, <span class="number">116</span>, <span class="number">123</span>, <span class="number">106</span>, <span class="number">112</span>, <span class="number">138</span>, <span class="number">123</span>,  <span class="number">86</span>, <span class="number">101</span>,  <span class="number">99</span>, <span class="number">136</span>,<span class="number">123</span>, <span class="number">117</span>, <span class="number">119</span>, <span class="number">105</span>, <span class="number">137</span>, <span class="number">123</span>, <span class="number">128</span>, <span class="number">125</span>, <span class="number">104</span>, <span class="number">109</span>, <span class="number">134</span>, <span class="number">125</span>, <span class="number">127</span>,<span class="number">105</span>, <span class="number">120</span>, <span class="number">107</span>, <span class="number">129</span>, <span class="number">116</span>, <span class="number">108</span>, <span class="number">132</span>, <span class="number">103</span>, <span class="number">136</span>, <span class="number">118</span>, <span class="number">102</span>, <span class="number">120</span>, <span class="number">114</span>,<span class="number">105</span>, <span class="number">115</span>, <span class="number">132</span>, <span class="number">145</span>, <span class="number">119</span>, <span class="number">121</span>, <span class="number">112</span>, <span class="number">139</span>, <span class="number">125</span>, <span class="number">138</span>, <span class="number">109</span>, <span class="number">132</span>, <span class="number">134</span>,<span class="number">156</span>, <span class="number">106</span>, <span class="number">117</span>, <span class="number">127</span>, <span class="number">144</span>, <span class="number">139</span>, <span class="number">139</span>, <span class="number">119</span>, <span class="number">140</span>,  <span class="number">83</span>, <span class="number">110</span>, <span class="number">102</span>,<span class="number">123</span>,<span class="number">107</span>, <span class="number">143</span>, <span class="number">115</span>, <span class="number">136</span>, <span class="number">118</span>, <span class="number">139</span>, <span class="number">123</span>, <span class="number">112</span>, <span class="number">118</span>, <span class="number">125</span>, <span class="number">109</span>, <span class="number">119</span>, <span class="number">133</span>,<span class="number">112</span>, <span class="number">114</span>, <span class="number">122</span>, <span class="number">109</span>, <span class="number">106</span>, <span class="number">123</span>, <span class="number">116</span>, <span class="number">131</span>, <span class="number">127</span>, <span class="number">115</span>, <span class="number">118</span>, <span class="number">112</span>, <span class="number">135</span>,<span class="number">115</span>, <span class="number">146</span>, <span class="number">137</span>, <span class="number">116</span>, <span class="number">103</span>, <span class="number">144</span>,  <span class="number">83</span>, <span class="number">123</span>, <span class="number">111</span>, <span class="number">110</span>, <span class="number">111</span>, <span class="number">100</span>, <span class="number">154</span>,<span class="number">136</span>, <span class="number">100</span>, <span class="number">118</span>, <span class="number">119</span>, <span class="number">133</span>, <span class="number">134</span>, <span class="number">106</span>, <span class="number">129</span>, <span class="number">126</span>, <span class="number">110</span>, <span class="number">111</span>, <span class="number">109</span>, <span class="number">141</span>,<span class="number">120</span>, <span class="number">117</span>, <span class="number">106</span>, <span class="number">149</span>, <span class="number">122</span>, <span class="number">122</span>, <span class="number">110</span>, <span class="number">118</span>, <span class="number">127</span>, <span class="number">121</span>, <span class="number">114</span>, <span class="number">125</span>, <span class="number">126</span>,<span class="number">114</span>, <span class="number">140</span>, <span class="number">103</span>, <span class="number">130</span>, <span class="number">141</span>, <span class="number">117</span>, <span class="number">106</span>, <span class="number">114</span>, <span class="number">121</span>, <span class="number">114</span>, <span class="number">133</span>, <span class="number">137</span>,  <span class="number">92</span>,<span class="number">121</span>, <span class="number">112</span>, <span class="number">146</span>,  <span class="number">97</span>, <span class="number">137</span>, <span class="number">105</span>,  <span class="number">98</span>, <span class="number">117</span>, <span class="number">112</span>,  <span class="number">81</span>,  <span class="number">97</span>, <span class="number">139</span>, <span class="number">113</span>,<span class="number">134</span>, <span class="number">106</span>, <span class="number">144</span>, <span class="number">110</span>, <span class="number">137</span>, <span class="number">137</span>, <span class="number">111</span>, <span class="number">104</span>, <span class="number">117</span>, <span class="number">100</span>, <span class="number">111</span>, <span class="number">101</span>, <span class="number">110</span>,<span class="number">105</span>, <span class="number">129</span>, <span class="number">137</span>, <span class="number">112</span>, <span class="number">120</span>, <span class="number">113</span>, <span class="number">133</span>, <span class="number">112</span>,  <span class="number">83</span>,  <span class="number">94</span>, <span class="number">146</span>, <span class="number">133</span>, <span class="number">101</span>,<span class="number">131</span>, <span class="number">116</span>, <span class="number">111</span>,  <span class="number">84</span>, <span class="number">137</span>, <span class="number">115</span>, <span class="number">122</span>, <span class="number">106</span>, <span class="number">144</span>, <span class="number">109</span>, <span class="number">123</span>, <span class="number">116</span>, <span class="number">111</span>,<span class="number">111</span>, <span class="number">133</span>, <span class="number">150</span>]</span><br><span class="line"><span class="comment"># 定义一个间隔大小</span></span><br><span class="line">a = <span class="number">2</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 得出组数</span></span><br><span class="line">bins = <span class="built_in">int</span>((<span class="built_in">max</span>(time) - <span class="built_in">min</span>(time)) / a)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 画出直方图</span></span><br><span class="line">plt.hist(time, bins, normed=<span class="number">1</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 指定刻度的范围，以及步长</span></span><br><span class="line">plt.xticks(<span class="built_in">list</span>(<span class="built_in">range</span>(<span class="built_in">min</span>(time), <span class="built_in">max</span>(time)))[::<span class="number">2</span>])</span><br><span class="line"></span><br><span class="line">plt.xlabel(<span class="string">&quot;电影时长大小&quot;</span>)</span><br><span class="line">plt.ylabel(<span class="string">&quot;电影的数据量&quot;</span>)</span><br><span class="line"></span><br><span class="line">plt.show()</span><br></pre></td></tr></table></figure>
<p><img src= "" data-lazy-src="E:%5Cpython%5C%E8%AF%BE%E7%A8%8B%E6%96%87%E4%BB%B6%E5%A4%B9%5C%E8%AF%BE%E4%BB%B6%E5%9B%BE%E7%89%87%5C484.%E7%94%B5%E5%BD%B1%E6%97%B6%E9%95%BF%E5%88%86%E5%B8%83%E6%97%A0%E7%BD%91%E6%A0%BC.png" alt="电影时长分布无网格"></p>
<h4 id="3-增加网格显示">3 增加网格显示</h4>
<p>为了更好将图形对应到</p>
<figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">plt.grid(<span class="literal">True</span>, <span class="attribute">linestyle</span>=<span class="string">&#x27;--&#x27;</span>, <span class="attribute">alpha</span>=0.5)</span><br></pre></td></tr></table></figure>
<h3 id="5-3-直方图的场景">5.3 直方图的场景</h3>
<ul>
<li>用于表示分布情况</li>
<li>通过直方图还可以观察和估计哪些数据比较集中，异常或者孤立的数据分布在何处</li>
</ul>
<p>例如：用户年龄分布，商品价格分布</p>
<h3 id="5-4-直方图与其他图表的对比">5.4 直方图与其他图表的对比</h3>
<ul>
<li>柱状图是以矩形的长度表示每一组的频数或数量，其宽度(表示类别)则是固定的，<strong>利于较小的数据集分析</strong>。</li>
<li>直方图是以矩形的长度表示每一组的频数或数量，宽度则表示各组的组距，因此其高度与宽度均有意义，利于<strong>展示大量数据集的统计结果</strong>。</li>
<li>由于分组数据具有连续性，<strong>直方图的各矩形通常是连续排列，而柱状图则是分开排列</strong>。</li>
</ul>
<h2 id="6-其他">6 其他</h2>
<h3 id="6-1-竖直线、水平线">6.1 竖直线、水平线</h3>
<p>axvline:画垂直于x轴的线</p>
<p>axcline：画垂直于y轴的线</p>
<p>帕累托图</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">def</span> <span class="title function_">percentage_accumulation</span>(<span class="params">series,per</span>):</span><br><span class="line">    <span class="keyword">return</span> series.sort_values(ascending=<span class="literal">False</span>)[:<span class="built_in">round</span>(series.shape[<span class="number">0</span>]/<span class="number">100</span>*per)].<span class="built_in">sum</span>()/(series.<span class="built_in">sum</span>())</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">percentage=[]</span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">100</span>):</span><br><span class="line">    percentage.append(percentage_accumulation(df[<span class="string">&quot;Positive Feedback Count&quot;</span>],i))</span><br><span class="line"><span class="comment"># 绘制帕累托图    </span></span><br><span class="line">plt.plot(percentage)</span><br><span class="line"></span><br><span class="line">plt.title(<span class="string">&quot;评论点赞数累计百分比&quot;</span>)</span><br><span class="line">plt.axvline(x=<span class="number">20</span>,color=<span class="string">&quot;r&quot;</span>,linewidth=<span class="number">1</span>)</span><br><span class="line">plt.axvline(x=<span class="number">53</span>,color=<span class="string">&quot;g&quot;</span>,linewidth=<span class="number">1</span>)</span><br><span class="line">plt.axhline(y=<span class="number">0.79</span>,color=<span class="string">&quot;r&quot;</span>,linewidth=<span class="number">1</span>)</span><br><span class="line">plt.axhline(y=<span class="number">1</span>,color=<span class="string">&quot;g&quot;</span>,linewidth=<span class="number">1</span>)</span><br><span class="line"></span><br><span class="line">plt.show()</span><br></pre></td></tr></table></figure>
<p><img src= "" data-lazy-src="E:/python/%E8%AF%BE%E7%A8%8B%E6%96%87%E4%BB%B6%E5%A4%B9/%E8%AF%BE%E4%BB%B6%E5%9B%BE%E7%89%87/908.png" alt=""></p>
<h3 id="6-2-seaborn">6.2 seaborn</h3>
<h4 id="1-kdeplot-核密度估计">1 kdeplot 核密度估计</h4>
<h3 id="非参数估计方法">非参数估计方法</h3>
<p>由于核密度估计方法不利用有关数据分布的先验知识，对数据分布不附加任何假定，是一种从数据样本本身出发研究数据分布特征的方法，因而，在统计学理论和应用领域均受到高度的重视。</p>
<p>在密度函数估计中有一种方法是被广泛应用的——<strong>直方图</strong>。如下图中的第一和第二幅图（名为Histogram和Histogram, bins shifted）。直方图的特点是简单易懂，但缺点在于以下三个方面：密度函数是不平滑的；密度函数受子区间（即每个直方体）<strong>宽度影响很大</strong>，同样的原始数据如果取不同的子区间范围，那么展示的结果可能是完全不同的。如下图中的前两个图，第二个图只是在第一个图的基础上，划分区间增加了0.75，但展现出的密度函数却看起来差异很大；直方图最多<strong>只能展示2维数据</strong>，如果维度更多则无法有效展示。</p>
<p><img src= "" data-lazy-src="E:/python/%E8%AF%BE%E7%A8%8B%E6%96%87%E4%BB%B6%E5%A4%B9/%E8%AF%BE%E4%BB%B6%E5%9B%BE%E7%89%87/935.png" alt=""></p>
<p>虽然采用不同的核函数都可以获得一致性的结论（整体趋势和密度分布规律性基本一致），但核密度函数也不是完美的。除了核算法的选择外，带宽（bandwidth）也会影响密度估计，过大或过小的带宽值都会影响估计结果。如上图中的最后三个图，名为Gaussian Kernel Density,bandwidth=0.75、Gaussian Kernel Density,bandwidth=0.25、Gaussian Kernel Density,bandwidth=0.55.</p>
<p><strong>总而言之，核密度就是用来估计密度的，如果你有一系列空间点数据，那么核密度估计往往是比较好的可视化方法</strong></p>
<p>核密度函数的原理比较简单，在我们知道某一事物的概率分布的情况下，如果<strong>某一个数在观察中出现了</strong>，我们可以认为这个数的<strong>概率密度很大</strong>，和这个数比较近的数的概率密度也会比较大，而那些离这个数远的数的概率密度会比较小。</p>
<p>基于这种想法，针对观察中的第一个数，我们可以用K去拟合我们想象中的那个远小近大概率密度。对每一个观察数拟合出的多个概率密度分布函数，取平均。如果某些数是比较重要的，则可以取加权平均。<strong>需要说明的一点是，核密度的估计并不是找到真正的分布函数。</strong></p>
<p>Note: 核密度估计其实就是通过核函数（如高斯）将每个数据点的<strong>数据+带宽</strong>当作核函数的参数，得到N个核函数，再线性叠加就形成了核密度的估计函数，归一化后就是核密度概率密度函数了。</p>
<p>KDE的概率密度函数公式得到后</p>
<p><img src= "" data-lazy-src="E:/python/%E8%AF%BE%E7%A8%8B%E6%96%87%E4%BB%B6%E5%A4%B9/%E8%AF%BE%E4%BB%B6%E5%9B%BE%E7%89%87/936.png" alt=""></p>
<blockquote>
<p>看到这个公式明白了，为什么x轴是小数时，y轴上的值会大于1，因为带宽为小数，而带宽又作分母，所以值会大于1</p>
<p>核密度函数，峰值就是出现次数最多的。</p>
</blockquote>
<h2 id="7-词云">7 词云</h2>
<p>WordCloud 词云图，显示主要的关键词（高频词）这种方式，非常方便</p>
<ul>
<li>from wordclound import WordClound</li>
</ul>
<p><img src= "" data-lazy-src="E:/python/%E8%AF%BE%E7%A8%8B%E6%96%87%E4%BB%B6%E5%A4%B9/%E8%AF%BE%E4%BB%B6%E5%9B%BE%E7%89%87/948.png" alt=""></p>
<p>了解了各项参数后，我们就可以自定义想要的词云图了。比如更换一下背景颜色和整体风格，就可以通过修改以下几项参数实现：</p>
<p><img src= "" data-lazy-src="E:/python/%E8%AF%BE%E7%A8%8B%E6%96%87%E4%BB%B6%E5%A4%B9/%E8%AF%BE%E4%BB%B6%E5%9B%BE%E7%89%87/949.png" alt=""></p>
<p><img src= "" data-lazy-src="E:/python/%E8%AF%BE%E7%A8%8B%E6%96%87%E4%BB%B6%E5%A4%B9/%E8%AF%BE%E4%BB%B6%E5%9B%BE%E7%89%87/950.png" alt=""></p>
<p>接下来，我们提升一点难度，通过设置 StopWords 去掉没有实际意义的「ONE」字符，然后将词云图绘制在我们自定义的一张图片上。</p>
<p><img src= "" data-lazy-src="E:/python/%E8%AF%BE%E7%A8%8B%E6%96%87%E4%BB%B6%E5%A4%B9/%E8%AF%BE%E4%BB%B6%E5%9B%BE%E7%89%87/951.png" alt=""></p>
<p></p>
<p>代码实现如下：</p>
<p><img src= "" data-lazy-src="E:/python/%E8%AF%BE%E7%A8%8B%E6%96%87%E4%BB%B6%E5%A4%B9/%E8%AF%BE%E4%BB%B6%E5%9B%BE%E7%89%87/952.png" alt=""></p>
<p>这里，首先通过 open() 方法读取文本文件，Image.open() 方法读取了背景图片，np.array 方法将图片转换为矩阵。</p>
<p>接着设置了词云自带的英文 StopWords 停止词，用来分割筛除文本中不需要的词汇，比如：a、an、the 这些。</p>
<p>然后，在 WordCloud 方法中，设置词云的具体参数。generate_from_text() 方法生成该词云，recolor() 则是根据图片色彩绘制词云文字颜色。最终的词云绘制效果如下：</p>
<p><img src= "" data-lazy-src="E:/python/%E8%AF%BE%E7%A8%8B%E6%96%87%E4%BB%B6%E5%A4%B9/%E8%AF%BE%E4%BB%B6%E5%9B%BE%E7%89%87/953.png" alt=""></p>
<p>原文链接：<a target="_blank" rel="noopener" href="https://blog.csdn.net/crhacq798/article/details/86569755">https://blog.csdn.net/crhacq798/article/details/86569755</a></p>
</article><div class="post-copyright"><div class="post-copyright__title"><span class="post-copyright-info"><h>数据分析 </h></span></div><div class="post-copyright__type"><span class="post-copyright-info"><a href="https://xiangmou123.gitee.io/xiangmou/posts/3311.html">https://xiangmou123.gitee.io/xiangmou/posts/3311.html</a></span></div><div class="post-copyright-m"><div class="post-copyright-m-info"><div class="post-copyright-a"><h>作者</h><div class="post-copyright-cc-info"><h>Fomalhaut🥝</h></div></div><div class="post-copyright-c"><h>发布于</h><div class="post-copyright-cc-info"><h>2020-03-07</h></div></div><div class="post-copyright-u"><h>更新于</h><div class="post-copyright-cc-info"><h>2023-02-23</h></div></div><div class="post-copyright-c"><h>许可协议</h><div class="post-copyright-cc-info"><a class="icon" rel="noopener" target="_blank" title="Creative Commons" href="https://creativecommons.org/"><i class="fab fa-creative-commons"></i></a><a rel="noopener" target="_blank" title="CC BY-NC-SA 4.0" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a></div></div></div></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/xiangmou/tags/Python/"><div class="tags-punctuation"><svg class="faa-tada icon" style="height:1.1em;width:1.1em;fill:currentColor;position:relative;top:2px;margin-right:3px" aria-hidden="true"><use xlink:href="#icon-sekuaibiaoqian"></use></svg></div>Python</a><a class="post-meta__tags" href="/xiangmou/tags/%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90/"><div class="tags-punctuation"><svg class="faa-tada icon" style="height:1.1em;width:1.1em;fill:currentColor;position:relative;top:2px;margin-right:3px" aria-hidden="true"><use xlink:href="#icon-sekuaibiaoqian"></use></svg></div>数据分析</a></div></div><link rel="stylesheet" href="/xiangmou/css/coin.css" media="defer" onload="this.media='all'"/><div class="post-reward"><button class="tip-button reward-button"><span class="tip-button__text">投喂作者</span><div class="coin-wrapper"><div class="coin"><div class="coin__middle"></div><div class="coin__back"></div><div class="coin__front"></div></div></div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="https://tuchuang.voooe.cn/images/2023/01/04/2.webp" target="_blank"><img class="post-qr-code-img" src= "" data-lazy-src="https://tuchuang.voooe.cn/images/2023/01/04/2.webp" alt="微信"/></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="https://tuchuang.voooe.cn/images/2023/01/04/20f8e49805975b8f8.webp" target="_blank"><img class="post-qr-code-img" src= "" data-lazy-src="https://tuchuang.voooe.cn/images/2023/01/04/20f8e49805975b8f8.webp" alt="支付宝"/></a><div class="post-qr-code-desc">支付宝</div></li></ul></div></button></div><audio id="coinAudio" src="https://npm.elemecdn.com/akilar-candyassets@1.0.36/audio/aowu.m4a"></audio><script defer="defer" src="/xiangmou/js/coin.js"></script><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/xiangmou/posts/3313.html"><img class="prev-cover" src= "" data-lazy-src="https://source.fomal.cc/img/default_cover_14.webp" onerror="onerror=null;src='/xiangmou/assets/r2.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Mongodb数据库 </div></div></a></div><div class="next-post pull-right"><a href="/xiangmou/posts/3310.html"><img class="next-cover" src= "" data-lazy-src="https://source.fomal.cc/img/default_cover_14.webp" onerror="onerror=null;src='/xiangmou/assets/r2.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Python基础 </div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/xiangmou/posts/3310.html" title="Python基础 "><img class="cover" src= "" data-lazy-src="https://source.fomal.cc/img/default_cover_14.webp" alt="cover"><div class="content is-center"><div class="date"><i class="fas fa-history fa-fw"></i> 2023-02-23</div><div class="title">Python基础 </div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div id="twikoo-wrap"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><svg class="meta_icon" style="width:22px;height:22px;position:relative;top:5px"><use xlink:href="#icon-mulu1"></use></svg><span style="font-weight:bold">目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link"><span class="toc-text">一 Jupyter notebook</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-%E6%9C%AC%E6%9C%BA%E6%89%93%E5%BC%80"><span class="toc-text">1 本机打开</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-cell"><span class="toc-text">2 cell</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#2-1cell%E6%93%8D%E4%BD%9C"><span class="toc-text">2.1cell操作</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-2-cell%E5%BF%AB%E6%8D%B7%E9%94%AE"><span class="toc-text">2.2 cell快捷键</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link"><span class="toc-text">二 Matplotlib</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-%E7%BB%98%E5%9B%BE%E6%9E%B6%E6%9E%84"><span class="toc-text">1 绘图架构</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-1-Matplotlib%E6%A1%86%E6%9E%B6%E6%9E%84%E6%88%90"><span class="toc-text">1.1 Matplotlib框架构成</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-%E5%90%8E%E7%AB%AF%E5%B1%82"><span class="toc-text">1 后端层</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-%E7%BE%8E%E5%B7%A5%E5%B1%82"><span class="toc-text">2 美工层</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-%E8%84%9A%E6%9C%AC%E5%B1%82"><span class="toc-text">3 脚本层</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-%E6%8A%98%E7%BA%BF%E5%9B%BE"><span class="toc-text">2 折线图</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#2-1-%E6%8A%98%E7%BA%BF%E5%9B%BE%E7%BB%98%E5%88%B6"><span class="toc-text">2.1 折线图绘制</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-matplotlib-pyplot%E6%A8%A1%E5%9D%97"><span class="toc-text">1 matplotlib.pyplot模块</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-%E6%8A%98%E7%BA%BF%E5%9B%BE%E7%BB%98%E5%88%B6%E4%B8%8E%E6%98%BE%E7%A4%BA"><span class="toc-text">2 折线图绘制与显示</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-%E4%BF%AE%E6%94%B9%E5%9B%BE%E5%BD%A2%E5%A4%A7%E5%B0%8F%E4%B8%8E%E5%9B%BE%E7%89%87%E4%BF%9D%E5%AD%98"><span class="toc-text">3 修改图形大小与图片保存</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-2-%E6%B8%A9%E5%BA%A6%E5%8F%98%E5%8C%96%E6%98%BE%E7%A4%BA"><span class="toc-text">2.2 温度变化显示</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-%E6%9E%84%E9%80%A0%E6%95%B0%E6%8D%AE%E3%80%81%E6%98%BE%E7%A4%BA"><span class="toc-text">1 构造数据、显示</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-%E8%87%AA%E5%AE%9A%E4%B9%89x-y%E5%88%BB%E5%BA%A6%E4%BB%A5%E5%8F%8A%E4%B8%AD%E6%96%87%E6%98%BE%E7%A4%BA"><span class="toc-text">2 自定义x,y刻度以及中文显示</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-%E5%A2%9E%E5%8A%A0%E6%A0%87%E9%A2%98%E3%80%81x%E8%BD%B4y%E8%BD%B4%E6%8F%8F%E8%BF%B0%E4%BF%A1%E6%81%AF"><span class="toc-text">3 增加标题、x轴y轴描述信息</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#4-%E5%86%8D%E6%B7%BB%E5%8A%A0%E4%B8%80%E4%B8%AA%E5%9F%8E%E5%B8%82%E7%9A%84%E6%B8%A9%E5%BA%A6%E5%8F%98%E5%8C%96"><span class="toc-text">4 再添加一个城市的温度变化</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#5-%E6%B7%BB%E5%8A%A0%E5%9B%BE%E4%BE%8B"><span class="toc-text">5 添加图例</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-3-%E5%A4%9A%E4%B8%AA%E5%9D%90%E6%A0%87%E7%B3%BB%E6%98%BE%E7%A4%BA"><span class="toc-text">2.3 多个坐标系显示</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-%E6%95%A3%E7%82%B9%E5%9B%BE"><span class="toc-text">3 散点图</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-%E6%9F%B1%E5%BD%A2%E5%9B%BE"><span class="toc-text">4 柱形图</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#4-1-%E5%B8%B8%E8%A7%81%E5%9B%BE%E5%BD%A2%E7%A7%8D%E7%B1%BB%E5%8F%8A%E6%84%8F%E4%B9%89"><span class="toc-text">4.1 常见图形种类及意义</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-2-%E7%94%B5%E5%BD%B1%E7%A5%A8%E6%9F%B1%E5%BD%A2%E5%9B%BE"><span class="toc-text">4.2 电影票柱形图</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-%E9%9C%80%E6%B1%82"><span class="toc-text">1 需求</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-%E7%BB%98%E5%88%B6"><span class="toc-text">2 绘制</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-%E6%AF%94%E8%BE%83%E7%9B%B8%E5%90%8C%E5%A4%A9%E6%95%B0%E7%9A%84%E7%A5%A8%E6%88%BF"><span class="toc-text">3 比较相同天数的票房</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5-%E7%9B%B4%E6%96%B9%E5%9B%BE"><span class="toc-text">5 直方图</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#5-1-%E7%9B%B4%E6%96%B9%E5%9B%BE-Histogram-%E4%BB%8B%E7%BB%8D"><span class="toc-text">5.1 直方图(Histogram)介绍</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%9B%B8%E5%85%B3%E6%A6%82%E5%BF%B5%EF%BC%9A"><span class="toc-text">相关概念：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-2-%E7%94%B5%E5%BD%B1%E6%97%B6%E9%95%BF%E5%88%86%E5%B8%83%E7%BB%98%E5%88%B6"><span class="toc-text">5.2 电影时长分布绘制</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-matplotlib-pyplot-hist-x-bins-None-normed-None-kwargs"><span class="toc-text">1 matplotlib.pyplot.hist(x, bins&#x3D;None, normed&#x3D;None, **kwargs)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-%E5%88%86%E6%9E%90"><span class="toc-text">2 分析</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-%E5%A2%9E%E5%8A%A0%E7%BD%91%E6%A0%BC%E6%98%BE%E7%A4%BA"><span class="toc-text">3 增加网格显示</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-3-%E7%9B%B4%E6%96%B9%E5%9B%BE%E7%9A%84%E5%9C%BA%E6%99%AF"><span class="toc-text">5.3 直方图的场景</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-4-%E7%9B%B4%E6%96%B9%E5%9B%BE%E4%B8%8E%E5%85%B6%E4%BB%96%E5%9B%BE%E8%A1%A8%E7%9A%84%E5%AF%B9%E6%AF%94"><span class="toc-text">5.4 直方图与其他图表的对比</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#6-%E5%85%B6%E4%BB%96"><span class="toc-text">6 其他</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#6-1-%E7%AB%96%E7%9B%B4%E7%BA%BF%E3%80%81%E6%B0%B4%E5%B9%B3%E7%BA%BF"><span class="toc-text">6.1 竖直线、水平线</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#6-2-seaborn"><span class="toc-text">6.2 seaborn</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-kdeplot-%E6%A0%B8%E5%AF%86%E5%BA%A6%E4%BC%B0%E8%AE%A1"><span class="toc-text">1 kdeplot 核密度估计</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%9D%9E%E5%8F%82%E6%95%B0%E4%BC%B0%E8%AE%A1%E6%96%B9%E6%B3%95"><span class="toc-text">非参数估计方法</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#7-%E8%AF%8D%E4%BA%91"><span class="toc-text">7 词云</span></a></li></ol></li></ol></div></div></div></div></main><footer id="footer" style="background-color: transparent;"><div id="footer-wrap"><div id="ft"><div class="ft-item-1"><div class="t-top"><div class="t-t-l"><p class="ft-t t-l-t">格言🧬</p><div class="bg-ad"><div>再看看那个光点，它就在这里，这是家园，这是我们 —— 你所爱的每一个人，你认识的一个人，你听说过的每一个人，曾经有过的每一个人，都在它上面度过他们的一生✨</div><div class="btn-xz-box"><a class="btn-xz" target="_blank" rel="noopener" href="https://stellarium.org/">点击开启星辰之旅</a></div></div></div><div class="t-t-r"><p class="ft-t t-l-t">猜你想看💡</p><ul class="ft-links"><li><a href="/posts/eec9786.html">魔改指南</a><a href="/box/nav/">网址导航</a></li><li><a href="/social/link/">我的朋友</a><a href="/comments/">留点什么</a></li><li><a href="/personal/about/">关于作者</a><a href="/archives/">文章归档</a></li><li><a href="/categories/">文章分类</a><a href="/tags/">文章标签</a></li><li><a href="/box/Gallery/">我的画廊</a><a href="/personal/bb/">我的唠叨</a></li><li><a href="/site/time/">建设进程</a><a href="/site/census/">网站统计</a></li></ul></div></div></div><div class="ft-item-2"><p class="ft-t">推荐友链⌛</p><div class="ft-img-group"><div class="img-group-item"><a target="_blank" rel="noopener" href="https://www.fomal.cc/" title="Fomalhaut🥝"><img src= "" data-lazy-src="https://lskypro.acozycotage.net/LightPicture/2022/12/60e5d4e39da7c077.webp" alt=""/></a></div><div class="img-group-item"><a href="javascript:void(0)" title="广告位招租"><img src= "" data-lazy-src="https://lskypro.acozycotage.net/LightPicture/2022/12/65307a5828af6790.webp" alt=""/></a></div><div class="img-group-item"><a href="javascript:void(0)" title="广告位招租"><img src= "" data-lazy-src="https://lskypro.acozycotage.net/LightPicture/2022/12/65307a5828af6790.webp" alt=""/></a></div><div class="img-group-item"><a href="javascript:void(0)" title="广告位招租"><img src= "" data-lazy-src="https://lskypro.acozycotage.net/LightPicture/2022/12/65307a5828af6790.webp" alt=""/></a></div><div class="img-group-item"><a href="javascript:void(0)" title="广告位招租"><img src= "" data-lazy-src="https://lskypro.acozycotage.net/LightPicture/2022/12/65307a5828af6790.webp" alt=""/></a></div><div class="img-group-item"><a href="javascript:void(0)" title="广告位招租"><img src= "" data-lazy-src="https://lskypro.acozycotage.net/LightPicture/2022/12/65307a5828af6790.webp" alt=""/></a></div><div class="img-group-item"><a href="javascript:void(0)" title="广告位招租"><img src= "" data-lazy-src="https://lskypro.acozycotage.net/LightPicture/2022/12/65307a5828af6790.webp" alt=""/></a></div><div class="img-group-item"><a href="javascript:void(0)" title="广告位招租"><img src= "" data-lazy-src="https://lskypro.acozycotage.net/LightPicture/2022/12/65307a5828af6790.webp" alt=""/></a></div></div></div></div><div class="copyright"><span><b>&copy;2022-2023</b></span><span><b>&nbsp;&nbsp;By Fomalhaut🥝</b></span></div><div id="workboard"></div><p id="ghbdages"><a class="github-badge" target="_blank" href="https://hexo.io/" style="margin-inline:5px" title="博客框架为Hexo_v6.3.0"><img src= "" data-lazy-src="https://sourcebucket.s3.ladydaily.com/badge/Frame-Hexo-blue.svg" alt=""/></a><a class="github-badge" target="_blank" href="https://butterfly.js.org/" style="margin-inline:5px" title="主题版本Butterfly_v4.3.1"><img src= "" data-lazy-src="https://sourcebucket.s3.ladydaily.com/badge/Theme-Butterfly-6513df.svg" alt=""/></a><a class="github-badge" target="_blank" href="https://vercel.com/" style="margin-inline:5px" title="本站采用多线部署，主线路托管于Vercel"><img src= "" data-lazy-src="https://sourcebucket.s3.ladydaily.com/badge/Hosted-Vercel-brightgreen.svg" alt=""/></a><a class="github-badge" target="_blank" href="https://user.51.la/" style="margin-inline:5px" title="本站数据分析得益于51la技术支持"><img src= "" data-lazy-src="https://sourcebucket.s3.ladydaily.com/badge/Analytics-51la-3db1eb.svg" alt=""/></a><a class="github-badge" target="_blank" href="https://icp.gov.moe/?keyword=20226665" style="margin-inline:5px" title="本站已加入萌ICP豪华套餐，萌ICP备20226665号"><img src= "" data-lazy-src="https://sourcebucket.s3.ladydaily.com/badge/萌ICP备-20226665-fe1384.svg" alt=""/></a><a class="github-badge" target="_blank" href="https://bitiful.dogecast.com/buckets" style="margin-inline:5px" title="本网站经Service Worker分流至缤纷云对象存储"><img src= "" data-lazy-src=" https://sourcebucket.s3.ladydaily.com/badge/Bucket-缤纷云-9c62da.svg" alt=""/></a><a class="github-badge" target="_blank" href="https://www.netdun.net/" style="margin-inline:5px" title="本站使用网盾星球提供CDN加速与防护"><img src= "" data-lazy-src="https://sourcebucket.s3.ladydaily.com/badge/CDN-网盾星球-fff2cc.svg" alt=""/></a><a class="github-badge" target="_blank" href="https://github.com/" style="margin-inline:5px" title="本网站源码由Github提供存储仓库"><img src= "" data-lazy-src=" https://sourcebucket.s3.ladydaily.com/badge/Source-Github-d021d6.svg" alt=""/></a></p></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><a class="icon-V hidden" onclick="switchNightMode()" title="浅色和深色模式转换"><svg width="25" height="25" viewBox="0 0 1024 1024"><use id="modeicon" xlink:href="#icon-moon"></use></svg></a><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button><button class="share" type="button" title="右键模式" onclick="changeMouseMode()"><i class="fas fa-mouse"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog right_side"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button class="share" type="button" title="分享链接" onclick="share()"><i class="fas fa-share-nodes"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i><span id="percent">0<span>%</span></span></button><button id="go-down" type="button" title="直达底部" onclick="btf.scrollToDest(document.body.scrollHeight, 500)"><i class="fas fa-arrow-down"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div class="js-pjax" id="rightMenu"><div class="rightMenu-group rightMenu-small"><a class="rightMenu-item" href="javascript:window.history.back();"><i class="fa fa-arrow-left"></i></a><a class="rightMenu-item" href="javascript:window.history.forward();"><i class="fa fa-arrow-right"></i></a><a class="rightMenu-item" href="javascript:window.location.reload();"><i class="fa fa-refresh"></i></a><a class="rightMenu-item" href="javascript:rmf.scrollToTop();"><i class="fa fa-arrow-up"></i></a></div><div class="rightMenu-group rightMenu-line hide" id="menu-text"><a class="rightMenu-item" href="javascript:rmf.copySelect();"><i class="fa fa-copy"></i><span>复制</span></a><a class="rightMenu-item" href="javascript:window.open(&quot;https://www.baidu.com/s?wd=&quot;+window.getSelection().toString());window.location.reload();"><i class="fa fa-search"></i><span>百度搜索</span></a></div><div class="rightMenu-group rightMenu-line hide" id="menu-too"><a class="rightMenu-item" href="javascript:window.open(window.getSelection().toString());window.location.reload();"><i class="fa fa-link"></i><span>转到链接</span></a></div><div class="rightMenu-group rightMenu-line hide" id="menu-paste"><a class="rightMenu-item" href="javascript:rmf.paste()"><i class="fa fa-copy"></i><span>粘贴</span></a></div><div class="rightMenu-group rightMenu-line hide" id="menu-post"><a class="rightMenu-item" href="#post-comment"><i class="fas fa-comment"></i><span>空降评论</span></a><a class="rightMenu-item" href="javascript:rmf.copyWordsLink()"><i class="fa fa-link"></i><span>复制本文地址</span></a></div><div class="rightMenu-group rightMenu-line hide" id="menu-to"><a class="rightMenu-item" href="javascript:rmf.openWithNewTab()"><i class="fa fa-window-restore"></i><span>新窗口打开</span></a><a class="rightMenu-item" id="menu-too" href="javascript:rmf.open()"><i class="fa fa-link"></i><span>转到链接</span></a><a class="rightMenu-item" href="javascript:rmf.copyLink()"><i class="fa fa-copy"></i><span>复制链接</span></a></div><div class="rightMenu-group rightMenu-line hide" id="menu-img"><a class="rightMenu-item" href="javascript:rmf.saveAs()"><i class="fa fa-download"></i><span>保存图片</span></a><a class="rightMenu-item" href="javascript:rmf.openWithNewTab()"><i class="fa fa-window-restore"></i><span>在新窗口打开</span></a><a class="rightMenu-item" href="javascript:rmf.copyLink()"><i class="fa fa-copy"></i><span>复制图片链接</span></a></div><div class="rightMenu-group rightMenu-line"><a class="rightMenu-item" href="javascript:randomPost()"><i class="fa fa-paper-plane"></i><span>随便逛逛</span></a><a class="rightMenu-item" href="javascript:switchNightMode();"><i class="fa fa-moon"></i><span>昼夜切换</span></a><a class="rightMenu-item" href="/personal/about/"><i class="fa fa-info-circle"></i><span>关于博客</span></a><a class="rightMenu-item" href="javascript:toggleWinbox();"><i class="fas fa-cog"></i><span>美化设置</span></a><a class="rightMenu-item" href="javascript:rmf.fullScreen();"><i class="fas fa-expand"></i><span>切换全屏</span></a><a class="rightMenu-item" href="javascript:window.print();"><i class="fa-solid fa-print"></i><span>打印页面</span></a></div></div><div><script src="/xiangmou/js/utils.js"></script><script src="/xiangmou/js/main.js"></script><script src="https://cdn.staticfile.org/fancyapps-ui/4.0.31/fancybox.umd.min.js"></script><script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/instant.page/5.1.0/instantpage.min.js" type="module"></script><script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/vanilla-lazyload/17.3.1/lazyload.iife.min.js"></script><script src="/xiangmou/js/search/local-search.js"></script><script async="async">var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())
setTimeout(function(){preloader.endLoading();}, 5000);
document.getElementById('loading-box').addEventListener('click',()=> {preloader.endLoading()})</script><div class="js-pjax"><script>(()=>{
  const init = () => {
    twikoo.init(Object.assign({
      el: '#twikoo-wrap',
      envId: '',
      region: '',
      onCommentLoaded: function () {
        btf.loadLightbox(document.querySelectorAll('#twikoo .tk-content img:not(.tk-owo-emotion)'))
      }
    }, null))
  }

  const getCount = () => {
    const countELement = document.getElementById('twikoo-count')
    if(!countELement) return
    twikoo.getCommentsCount({
      envId: '',
      region: '',
      urls: [window.location.pathname],
      includeReply: false
    }).then(function (res) {
      countELement.innerText = res[0].count
    }).catch(function (err) {
      console.error(err);
    });
  }

  const runFn = () => {
    init()
    
  }

  const loadTwikoo = () => {
    if (typeof twikoo === 'object') {
      setTimeout(runFn,0)
      return
    } 
    getScript('https://cdn.staticfile.org/twikoo/1.6.8/twikoo.all.min.js').then(runFn)
  }

  if ('Twikoo' === 'Twikoo' || !true) {
    if (true) btf.loadComment(document.getElementById('twikoo-wrap'), loadTwikoo)
    else loadTwikoo()
  } else {
    window.loadOtherComment = () => {
      loadTwikoo()
    }
  }
})()</script></div><script src="https://cdn.staticfile.org/jquery/3.6.3/jquery.min.js"></script><script async src="https://cdn1.tianli0.top/npm/vue@2.6.14/dist/vue.min.js"></script><script async src="https://cdn1.tianli0.top/npm/element-ui@2.15.6/lib/index.js"></script><script async src="https://cdn.bootcdn.net/ajax/libs/clipboard.js/2.0.11/clipboard.min.js"></script><script defer type="text/javascript" src="https://cdn1.tianli0.top/npm/sweetalert2@8.19.0/dist/sweetalert2.all.js"></script><script async src="//npm.elemecdn.com/pace-js@1.2.4/pace.min.js"></script><script defer src="https://cdn1.tianli0.top/gh/nextapps-de/winbox/dist/winbox.bundle.min.js"></script><script async src="//at.alicdn.com/t/c/font_3586335_hsivh70x0fm.js"></script><script async src="//at.alicdn.com/t/c/font_3636804_gr02jmjr3y9.js"></script><script async src="//at.alicdn.com/t/c/font_3612150_kfv55xn3u2g.js"></script><script async src="https://cdn.wpon.cn/2022-sucai/Gold-ingot.js"></script><canvas id="universe"></canvas><canvas id="snow"></canvas><script defer src="/js/fomal.js"></script><link rel="stylesheet" href="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/aplayer/1.10.1/APlayer.min.css" media="print" onload="this.media='all'"><script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/aplayer/1.10.1/APlayer.min.js"></script><script src="https://cdn1.tianli0.top/npm/js-heo@1.0.12/metingjs/Meting.min.js"></script><script src="https://lib.baomitu.com/pjax/0.2.8/pjax.min.js"></script><script>let pjaxSelectors = ["head > title","#config-diff","#body-wrap","#rightside-config-hide","#rightside-config-show","#web_bg",".js-pjax","#bibi","body > title","#app","#tag-echarts","#posts-echart","#categories-echarts"]

var pjax = new Pjax({
  elements: 'a:not([target="_blank"])',
  selectors: pjaxSelectors,
  cacheBust: false,
  analytics: false,
  scrollRestoration: false
})

document.addEventListener('pjax:send', function () {

  // removeEventListener scroll 
  window.tocScrollFn && window.removeEventListener('scroll', window.tocScrollFn)
  window.scrollCollect && window.removeEventListener('scroll', scrollCollect)

  typeof preloader === 'object' && preloader.initLoading()
  document.getElementById('rightside').style.cssText = "opacity: ''; transform: ''"
  
  if (window.aplayers) {
    for (let i = 0; i < window.aplayers.length; i++) {
      if (!window.aplayers[i].options.fixed) {
        window.aplayers[i].destroy()
      }
    }
  }

  typeof typed === 'object' && typed.destroy()

  //reset readmode
  const $bodyClassList = document.body.classList
  $bodyClassList.contains('read-mode') && $bodyClassList.remove('read-mode')

  typeof disqusjs === 'object' && disqusjs.destroy()
})

document.addEventListener('pjax:complete', function () {
  window.refreshFn()

  document.querySelectorAll('script[data-pjax]').forEach(item => {
    const newScript = document.createElement('script')
    const content = item.text || item.textContent || item.innerHTML || ""
    Array.from(item.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value))
    newScript.appendChild(document.createTextNode(content))
    item.parentNode.replaceChild(newScript, item)
  })

  GLOBAL_CONFIG.islazyload && window.lazyLoadInstance.update()

  typeof chatBtnFn === 'function' && chatBtnFn()
  typeof panguInit === 'function' && panguInit()

  // google analytics
  typeof gtag === 'function' && gtag('config', '', {'page_path': window.location.pathname});

  // baidu analytics
  typeof _hmt === 'object' && _hmt.push(['_trackPageview',window.location.pathname]);

  typeof loadMeting === 'function' && document.getElementsByClassName('aplayer').length && loadMeting()

  // prismjs
  typeof Prism === 'object' && Prism.highlightAll()

  typeof preloader === 'object' && preloader.endLoading()
})

document.addEventListener('pjax:error', (e) => {
  if (e.request.status === 404) {
    pjax.loadUrl('/404.html')
  }
})</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><!-- hexo injector body_end start --> <script data-pjax>if(document.getElementById('recent-posts') && (location.pathname ==='/'|| '/' ==='all')){
    var parent = document.getElementById('recent-posts');
    var child = '<div class="recent-post-item" style="width:100%;height: auto"><div id="catalog_magnet"><div class="magnet_item"><a class="magnet_link" href="https://xiangmou123.gitee.io/xiangmou/categories/演示/"><div class="magnet_link_context" style=""><span style="font-weight:500;flex:1">🍥 小Fの案例演示笔记 (1)</span><span style="padding:0px 4px;border-radius: 8px;"><i class="fas fa-arrow-circle-right"></i></span></div></a></div><div class="magnet_item" style="visibility: hidden"></div><div class="magnet_item" style="visibility: hidden"></div><a class="magnet_link_more"  href="https://xiangmou123.gitee.io/xiangmou/categories/" style="flex:1;text-align: center;margin-bottom: 10px;">查看更多...</a></div></div>';
    console.log('已挂载magnet')
    parent.insertAdjacentHTML("afterbegin",child)}
     </script><style>#catalog_magnet{flex-wrap: wrap;display: flex;width:100%;justify-content:space-between;padding: 10px 10px 0 10px;align-content: flex-start;}.magnet_item{flex-basis: calc(33.333333333333336% - 5px);background: #e9e9e9;margin-bottom: 10px;border-radius: 8px;transition: all 0.2s ease-in-out;}.magnet_item:hover{background: var(--text-bg-hover)}.magnet_link_more{color:#555}.magnet_link{color:black}.magnet_link:hover{color:white}@media screen and (max-width: 600px) {.magnet_item {flex-basis: 100%;}}.magnet_link_context{display:flex;padding: 10px;font-size:16px;transition: all 0.2s ease-in-out;}.magnet_link_context:hover{padding: 10px 20px;}</style>
    <style></style><script data-pjax>
  function butterfly_swiper_injector_config(){
    var parent_div_git = document.getElementById('recent-posts');
    var item_html = '<div class="recent-post-item" style="height: auto;width: 100%"><div class="blog-slider swiper-container-fade swiper-container-horizontal" id="swiper_container"><div class="blog-slider__wrp swiper-wrapper" style="transition-duration: 0ms;"><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/2013454d.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src= "" data-lazy-src="https://source.fomal.cc/img/default_cover_14.webp" alt="" onerror="this.src=https://unpkg.zhimg.com/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2022-08-09</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/2013454d.html&quot;);" href="javascript:void(0);" alt="">Markdown语法与外挂标签写法汇总</a><div class="blog-slider__text">🥧本文汇总Markdown格式以及外挂标签在网页端的渲染效果，可作为文档进行查询</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/2013454d.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div></div><div class="blog-slider__pagination swiper-pagination-clickable swiper-pagination-bullets"></div></div></div>';
    console.log('已挂载butterfly_swiper')
    parent_div_git.insertAdjacentHTML("afterbegin",item_html)
    }
  var elist = 'undefined'.split(',');
  var cpage = location.pathname;
  var epage = '/';
  var flag = 0;

  for (var i=0;i<elist.length;i++){
    if (cpage.includes(elist[i])){
      flag++;
    }
  }

  if ((epage ==='all')&&(flag == 0)){
    butterfly_swiper_injector_config();
  }
  else if (epage === cpage){
    butterfly_swiper_injector_config();
  }
  </script><script defer src="https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiper.min.js"></script><script defer data-pjax src="https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiper_init.js"></script><div class="js-pjax"><script async="async">var arr = document.getElementsByClassName('recent-post-item');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__zoomIn');
    arr[i].setAttribute('data-wow-duration', '2s');
    arr[i].setAttribute('data-wow-delay', '200ms');
    arr[i].setAttribute('data-wow-offset', '30');
    arr[i].setAttribute('data-wow-iteration', '1');
  }</script><script async="async">var arr = document.getElementsByClassName('card-widget');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__zoomIn');
    arr[i].setAttribute('data-wow-duration', '2s');
    arr[i].setAttribute('data-wow-delay', '200ms');
    arr[i].setAttribute('data-wow-offset', '30');
    arr[i].setAttribute('data-wow-iteration', '1');
  }</script></div><script defer src="https://npm.elemecdn.com/hexo-butterfly-wowjs/lib/wow.min.js"></script><script defer src="https://npm.elemecdn.com/hexo-butterfly-wowjs/lib/wow_init.js"></script><script data-pjax src="https://npm.elemecdn.com/hexo-filter-gitcalendar/lib/gitcalendar.js"></script><script data-pjax>
  function gitcalendar_injector_config(){
      var parent_div_git = document.getElementById('gitZone');
      var item_html = '<div class="recent-post-item" id="gitcalendarBar" style="width:100%;height:auto;padding:10px;"><style>#git_container{min-height: 320px}@media screen and (max-width:650px) {#git_container{min-height: 0px}}</style><div id="git_loading" style="width:10%;height:100%;margin:0 auto;display: block;"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 50 50" style="enable-background:new 0 0 50 50" xml:space="preserve"><path fill="#d0d0d0" d="M25.251,6.461c-10.318,0-18.683,8.365-18.683,18.683h4.068c0-8.071,6.543-14.615,14.615-14.615V6.461z" transform="rotate(275.098 25 25)"><animatetransform attributeType="xml" attributeName="transform" type="rotate" from="0 25 25" to="360 25 25" dur="0.6s" repeatCount="indefinite"></animatetransform></path></svg><style>#git_container{display: none;}</style></div><div id="git_container"></div></div>';
      parent_div_git.insertAdjacentHTML("afterbegin",item_html)
      console.log('已挂载gitcalendar')
      }

    if( document.getElementById('gitZone') && (location.pathname ==='/site/census/'|| '/site/census/' ==='all')){
        gitcalendar_injector_config()
        GitCalendarInit("/api?null",['#d9e0df', '#c6e0dc', '#a8dcd4', '#9adcd2', '#89ded1', '#77e0d0', '#5fdecb', '#47dcc6', '#39dcc3', '#1fdabe', '#00dab9'],'null')
    }
  </script><!-- hexo injector body_end end --></body></html>